Reputation: 43
I have problem with executing a jar file that creates a derby connection.
I am using netbeans; while netbeans is open the jar is executed correctly, but when I close the netbeans then I cannot connect to the database. This gives an error that the database is not found.
Code is as follows:
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
Statement stmt=con.createStatement();
rs = stmt.executeQuery("select * from login");
while(rs.next())
{
username[i] = rs.getString(3);
password[i] =rs.getString(8);
i++;
}
}
catch(Exception e){System.out.println(e);}
Jar execution error is
java.sql.SQLNoonTransientConnectionException: java.net.ConnectionException : Error connecting to server localhost on port 1527 with massage Connection refused : connect
What should I do to correct the problem?
Upvotes: 1
Views: 555
Reputation: 12883
Netbeans is running Derby for you. Look under Services->Databases->Java DB (probably under Java DB). When NB starts the DB, your application connects to that instance, and it's fine.
When you shut down Netbeans, it stops the Derby server and your application won't run. So you either need to switch to an embedded Derby configuration, or run a Derby database server somewhere for your application to use.
Upvotes: 1