Deploy Java Application with Embedded Derby Databa

2019-09-01 03:29发布

问题:

Am developing a java desktop application using Netbeans 1.8 IDE, the application will use embedded derby database to store data. The connection to the derby database is by the following.

 final String host = "jdbc:derby:C:\\Users\\Faisal\\.netbeans- 
 derby\\Wa_Poly";
 final String uName = "APP";
 final String uPass = "12345"; 

the following code snippet is used to connect to the database.

try (Connection con = DriverManager.getConnection(host, uName, uPass)) {
        try (Statement pstm = 
          con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,  
          ResultSet.CONCUR_UPDATABLE)) {
            try (ResultSet rslt = pstm.executeQuery(newRowSQL + sortby)) {
                bd = getData(rslt);
            }

to deploy the application , I added the database to the dist folder generated by the Netbeans. But any time I run the application , it is not able to connect to the Wa_Poly database Any suggestion is welcomed

回答1:

In host var you specified different path than to your dist folder. If you put your db to your dist folder, it should be sufficient to have something like this

final String host = "jdbc:derby:Wa_Poly";

Do you load JDBC driver properly?

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

Note that for further investigation it would be good to provide more code.