h2

Executing script file in h2 database

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 05:12:31
问题 First of all I would like to say am new to h2 database. I need to execute a sql script file in h2 database. I have a script file test.sql and I want to execute this in h2 database. Is it possible? 回答1: You can use the RUNSCRIPT SQL statement: RUNSCRIPT FROM 'test.sql' or you can use the RunScript standalone / command line tool: java -cp h2*.jar org.h2.tools.RunScript -url jdbc:h2:~/test -script test.sql You can also use the RunScript tool within an application: RunScript.execute(conn, new

Insert & fetch java.time.LocalDate objects to/from an SQL database such as H2

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 05:12:27
How to insert and fetch java.time types such as LocalDate via JDBC to an SQL database such as the H2 Database Engine ? The old way using PreparedStatement::setDate and ResultSet::getDate works for the legacy java.sql.Date type. I want to avoid using these troublesome old date-time classes. What is the modern way for sending java.time types through a JDBC driver ? We have two routes to exchanging java.time objects through JDBC: JDBC 4.2 compliant drivers If your JDBC driver complies with the JDBC 4.2 specification or later, you can deal directly with the java.time objects. Older drivers, before

Initialize database without XML configuration, but using @Configuration

非 Y 不嫁゛ 提交于 2019-11-27 05:11:04
问题 I would like to know how to initialize a database without having to create an XML file. I already use this kind of initialization that works fine, but in my current case I don't want to create an XML: <jdbc:initialize-database data-source="dataSource"> <jdbc:script location="classpath:com/foo/sql/db-schema.sql"/> <jdbc:script location="classpath:com/foo/sql/db-test-data.sql"/> </jdbc:initialize-database> I know I can create an embedded database with: EmbeddedDatabaseBuilder builder = new

How to run H2 database in server mode?

我的梦境 提交于 2019-11-27 04:02:59
问题 How to start H2 database in server mode. I need to start it from my application.I tried the following code: server = Server.createTcpServer().start(); Here is the properties for the connection: javabase.jdbc.url = jdbc:h2:tcp://localhost:9092/nio:~/source/db/database/db;AUTO_SERVER=TRUE javabase.jdbc.driver = org.h2.Driver javabase.jdbc.username = sa javabase.jdbc.password = When I run the program I got the following error: client.db.exception.DAOException: org.h2.jdbc.JdbcSQLException:

Can I have H2 autocreate a schema in an in-memory database?

人走茶凉 提交于 2019-11-27 04:02:19
问题 (I've already seen the H2 database In memory - Init schema via Spring/Hibernate question; it is not applicable here.) I'd like to know if there's a setting in H2 that will allow me to auto-create a schema upon connecting to it. If it helps, I'm only interested in the in-memory case. H2 supports various semicolon-separated modifiers at the end of the URL, but I didn't find one for automatically creating a schema. Is there such a feature? 回答1: Yes, H2 supports executing SQL statements when

Embedding the Java h2 database programmatically

↘锁芯ラ 提交于 2019-11-27 03:40:14
At the moment we use HSQLDB as an embedded database, but we search for a database with less memory footprint as the data volume grows. Derby / JavaDB is not an option at the moment because it stores properties globally in the system properties. So we thought of h2 . While we used HSQLDB we created a Server-object, set the parameters and started it. This is described here (and given as example in the class org.hsqldb.test.TestBase). The question is: Can this be done analogous with the h2 database, too? Do you have any code samples for that? Scanning the h2-page, I did not find an example. From

Why is my embedded h2 program writing to a .mv.db file

江枫思渺然 提交于 2019-11-27 03:01:56
问题 I followed the quickstart guide on the h2 database website to create a new database a table and insert some data. The application runs smooth and can read and write to the database without problems. Quickstart h2 Add the h2*.jar to the classpath (H2 does not have any dependencies) Use the JDBC driver class: org.h2.Driver The database URL jdbc:h2:~/test opens the database test in your user home directory A new database is automatically created Now i want to look at the data with the web

Populate JFreechart TimeSeriesCollection from Mysql DB?

可紊 提交于 2019-11-27 02:13:05
I'm trying to make a chart in my application that returns me the temperature of days during the months. This chart is a JFreechart TimeSeriesCollection, and I am unable to have the graph read correct data from the database. It shows some of the values, but not all of them, and does not show the correct time. To fix this, I tried to implement the graph as posted here , but still could not solve my problem, even having gone to see this question , as people suggested public class NewClass extends ApplicationFrame { Connection conexao = null; PreparedStatement pst= null; ResultSet rs = null;

Accessing play project database with h2-browser

安稳与你 提交于 2019-11-27 01:17:20
问题 I am having some trouble accessing the mem database via the h2-browser on a Play framework project. With the configuration below, that I think is the correct one (apparently not!) I am getting a h2-browser, but with no tables (beside schema, that is), even though I have applied some migrations. What am I missing here? Thanks in advance. conf/application.conf: db.default.driver=org.h2.Driver db.default.url="jdbc:h2:mem:play" db.default.user=sa db.default.password="" 回答1: When you are using in

insert a BLOB via a sql script?

南笙酒味 提交于 2019-11-27 00:28:18
问题 I have an H2 database (http://www.h2database.com) and I'd like to insert a file into a BLOB field via a plain simple sql script (to populate a test database for instance). I know how to do that via the code but I cannot find how to do the sql script itself. I tried to pass the path , i.e. INSERT INTO mytable (id,name,file) VALUES(1,'file.xml',/my/local/path/file.xml); but this fails. Within the code (java for instance), it's easy to create a File object and pass that in, but directly from a