You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Brandon Dohman <B-...@gotcg.net> on 2008/04/30 17:22:29 UTC
issues when connecting to a database
I've been working to setup the ability for my java code to start and connect to my server from within the code, w/out having to do it through netbeans. However, I keep running into issues. I've tried connecting both ways, 1 through using this line
Process p = Runtime.getRuntime().exec("java -jar %DERBY_HOME%/lib/derbyrun.jar server start");
And another through using this line.
Process p = Runtime.getRuntime().exec("C:\\javadb\\bin\\startnetworkserver.bat");
Here is the error code I receive with my first line
sql ex in connecting to db java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect
java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DBServer.conversation.<init>(conversation.java:102)
at DBServer.DBServer.run(DBServer.java:110)
Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
at org.apache.derby.client.am.Connection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
... 5 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
Here is the error code I receive with my second line
sql ex in connecting to db The connection was refused because the database HMDATABASE was not found.
java.sql.SQLNonTransientConnectionException: The connection was refused because the database HMDATABASE was not found.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DBServer.conversation.<init>(conversation.java:102)
at DBServer.DBServer.run(DBServer.java:110)
Caused by: org.apache.derby.client.am.DisconnectException: The connection was refused because the database HMDATABASE was not found.
at org.apache.derby.client.net.NetConnectionReply.parseRDBNFNRM(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseAccessRdbError(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseACCRDBreply(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.readAccessDatabase(Unknown Source)
at org.apache.derby.client.net.NetConnection.readSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
... 5 more
Here is the code I'm using to start the server
try{
Process p = Runtime.getRuntime().exec("java -jar %DERBY_HOME%/lib/derbyrun.jar server start");
// or this line, I've tried it both ways
// Process p = Runtime.getRuntime().exec("C:\\javadb\\bin\\startnetworkserver.bat");
// p.waitFor();
}catch (Exception e ){
System.out.println("Exception in launching db " + e.getMessage());
JOptionPane.showMessageDialog(null,"Application: Exception in starting database " + e.getMessage());
}
And here is the code I'm using to connect to the database
String driverName = "org.apache.derby.jdbc.ClientDriver";
Class.forName(driverName);
String url = "jdbc:derby://localhost:1527/HMDATABASE";
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
I've gone through and set the java home and derby home as it shows in the guide, but still no avail.
My connect string on the runtime panel - databases is
jdbc:derby://localhost:1527/Patron_DB [hmadmin on HMADMIN]
If more information is needed please let me know. I hope my email isn't too confusing
Thanks for the help.
Re: issues when connecting to a database
Posted by Rick Hillegas <Ri...@Sun.COM>.
Hi Brandon,
From the stack trace, it appears that the engine doesn't know where
your database lives. From the server startup command and connection URL,
it appears that Derby is looking for the database in the current
directory of the server process. You can modify that startup command to
point the system property "derby.system.home" at the directory which
holds your databases. Please see the Developer's Guide section titled
"Defining the system directory". Alternatively, you can specify the full
path to your database on the connection URL. Please see the Developer's
Guide section titled "Connecting to databases outside the system directory".
Hope this helps,
-Rick
Brandon Dohman wrote:
> I've been working to setup the ability for my java code to start and
> connect to my server from within the code, w/out having to do it
> through netbeans. However, I keep running into issues. I've tried
> connecting both ways, 1 through using this line
>
> Process p = Runtime.getRuntime().exec("java -jar
> %DERBY_HOME%/lib/derbyrun.jar server start");
>
> And another through using this line.
>
> Process p =
> Runtime.getRuntime().exec("C:\\javadb\\bin\\startnetworkserver.bat");
>
>
>
> Here is the error code I receive with my first line
>
>
> sql ex in connecting to db java.net.ConnectException : Error
> connecting to server localhost on port 1527 with message Connection
> refused: connect
> java.sql.SQLNonTransientConnectionException: java.net.ConnectException
> : Error connecting to server localhost on port 1527 with message
> Connection refused: connect.
> at
> org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown
> Source)
> at
> org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
> at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
> at java.sql.DriverManager.getConnection(DriverManager.java:582)
> at java.sql.DriverManager.getConnection(DriverManager.java:185)
> at DBServer.conversation.<init>(conversation.java:102)
> at DBServer.DBServer.run(DBServer.java:110)
> Caused by: org.apache.derby.client.am.DisconnectException:
> java.net.ConnectException : Error connecting to server localhost on
> port 1527 with message Connection refused: connect.
> at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
> at org.apache.derby.client.net.NetConnection.newAgent_(Unknown
> Source)
> at org.apache.derby.client.am.Connection.<init>(Unknown Source)
> at org.apache.derby.client.net.NetConnection.<init>(Unknown
> Source)
> at org.apache.derby.client.net.NetConnection40.<init>(Unknown
> Source)
> at
> org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown
> Source)
> ... 5 more
> Caused by: java.net.ConnectException: Connection refused: connect
> at java.net.PlainSocketImpl.socketConnect(Native Method)
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
> at
> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
> Here is the error code I receive with my second line
>
> sql ex in connecting to db The connection was refused because the
> database HMDATABASE was not found.
> java.sql.SQLNonTransientConnectionException: The connection was
> refused because the database HMDATABASE was not found.
> at
> org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown
> Source)
> at
> org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
> at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
> at java.sql.DriverManager.getConnection(DriverManager.java:582)
> at java.sql.DriverManager.getConnection(DriverManager.java:185)
> at DBServer.conversation.<init>(conversation.java:102)
> at DBServer.DBServer.run(DBServer.java:110)
> Caused by: org.apache.derby.client.am.DisconnectException: The
> connection was refused because the database HMDATABASE was not found.
> at
> org.apache.derby.client.net.NetConnectionReply.parseRDBNFNRM(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnectionReply.parseAccessRdbError(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnectionReply.parseACCRDBreply(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnectionReply.readAccessDatabase(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnection.readSecurityCheckAndAccessRdb(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnection.flowSecurityCheckAndAccessRdb(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown
> Source)
> at
> org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
> at org.apache.derby.client.net.NetConnection.<init>(Unknown
> Source)
> at org.apache.derby.client.net.NetConnection40.<init>(Unknown
> Source)
> at
> org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown
> Source)
> ... 5 more
>
>
>
>
> Here is the code I'm using to start the server
>
> try{
> Process p = Runtime.getRuntime().exec("java -jar
> %DERBY_HOME%/lib/derbyrun.jar server start");
> // or this line, I've tried it both ways
> // Process p =
> Runtime.getRuntime().exec("C:\\javadb\\bin\\startnetworkserver.bat");
> // p.waitFor();
> }catch (Exception e ){
> System.out.println("Exception in launching db " +
> e.getMessage());
> JOptionPane.showMessageDialog(null,"Application: Exception
> in starting database " + e.getMessage());
> }
>
> And here is the code I'm using to connect to the database
>
> String driverName = "org.apache.derby.jdbc.ClientDriver";
> Class.forName(driverName);
> String url = "jdbc:derby://localhost:1527/HMDATABASE";
> String username = "username";
> String password = "password";
> connection = DriverManager.getConnection(url, username,
> password);
>
>
> I've gone through and set the java home and derby home as it shows in
> the guide, but still no avail.
>
> My connect string on the runtime panel - databases is
>
> jdbc:derby://localhost:1527/Patron_DB [hmadmin on HMADMIN]
>
> If more information is needed please let me know. I hope my email
> isn't too confusing
>
>
> Thanks for the help.