How to use Java DB (called Derby) with sleep mode

Hi guys, I can connect Derby via Eclipse Database Development, but I cannot connect Derby with the same URL with Eclipse Database Development via Hibernate. Error: "Caused by: java.sql.SQLException: Another instance of Derby may have already loaded the database"

+3
source share
2 answers

Just finished a project that did this using Derby with Hibernate a couple of days ago. (He works with Derby in the same JVM.)

As I understand it, when you use the Embedded driver, by default it starts the database instance as part of the driver and as long as you hang on the connection in which the database is running. But for Hibernate, he likes to have DataSourceone that should be the source of the union data.

The above answer is correct, it’s actually good to run Derby as a network database server, even if your in the same JVM. You can still use the built-in JDBC driver, which seems to know when the database you are connecting to is online and is configured accordingly. (It also allows you to use a third-party tool to connect to the database, view and edit data and circuits during its operation, which are very convenient for debugging.)

System.setProperty("derby.system.home", applicationHome);

NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName(m_address),port);

serverControl.start(new PrintWriter(System.out, true)); 

DataSource JNDI. Hibernate , , JNDI.

EmbeddedConnectionPoolDataSource40 dataSource = new EmbeddedConnectionPoolDataSource40();
dataSource.setDatabaseName(databaseName);
dataSource.setUser(username);
dataSource.setPassword(password);

EmbeddedConnectionPoolDataSource40 - DataSource DataSource, , . Apache Commons DBCP , DataSource EmbeddedConnectionPoolDataSource40.

+2

, Derby , .

, JVM JVM.

Eclipse JVM, eclipse. , Derby .

+2

Source: https://habr.com/ru/post/1719275/


All Articles