How to integrate JavaDB database into my main java package

I am working on a desktop application that uses JavaDB. I am using NetBeans 6.8 and JDK 6 Update 20

I created the database I needed and connected to it through my application using ClientDriver :

  String driver = "org.apache.derby.jdbc.ClientDriver"; String connectionURL = "jdbc:derby://localhost:1527/myDB;create=true;user=user;password=pass"; try { Class.forName(driver); } catch (java.lang.ClassNotFoundException e) { e.printStackTrace(); } try { schedoDBConnection = DriverManager.getConnection(connectionURL); } catch (Exception e) { e.printStackTrace(); } 

It works great. But in this case, the database service comes from NetBeans. If I transfer the application to another computer, I will not be able to access my database. How can I integrate my JavaDB into my application?

+4
source share
3 answers

If I transfer my application to another computer, I will not be able to access my database. How can I integrate my JavaDB into my application?

NetBeans starts Derby in network server mode , and Derby runs in another JVM. If you want to embed your database in an application, you need to run Derby in native mode from your application. To do this, use the EmbeddedDriver provided by derby.jar .

 /* If you are running on JDK 6 or higher, you do not need to invoke Class.forName(). In that environment, the EmbeddedDriver loads automatically. */ Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection conn = DriverManager.getConnection("jdbc:derby:sample"); 

By default, the database will be created / loaded from the working directory. If you want more control, we recommend setting the system property derby.system.home . See Using Java DB in desktop applications .

see also

+3
source

The database does not come from Netbeans; it is built into the JDK itself.

Clients must have a JDBC JAR driver for them. If you use the database as a server, your users will need to start the server. Perhaps this is the part that Netbeans is doing for you that needs to be replaced.

0
source

after creating db derby and connecting to localhost you need to add a line to the derby.properties file found in your directory database

 derby.drda.host=10.0.0.40 //example IPAddress 

save and go to connection in netbeans and change localhost to ipaddress

0
source

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


All Articles