在Eclipse中连接到derby数据库

时间:2018-08-07 06:16:39

标签: java eclipse jvm derby

我需要使用eclipse建立一个derby数据库连接。这是我的代码-

'String driver = "org.apache.derby.jdbc.ClientDriver";
 String dbName="jdbcDemoDB";
// define the Derby connection URL to use 
String connectionURL = "jdbc:derby://localhost:1527/" + dbName+";create=true";
Connection conn = null;'
try {
        conn = DriverManager.getConnection(connectionURL);       
        System.out.println("Connected to database " + dbName);
        s = conn.createStatement();
}
catch (Throwable e)  {   
        /*       Catch all exceptions and pass them to 
         *       the Throwable.printStackTrace method  */
        System.out.println(" . . . exception thrown:");
        e.printStackTrace(System.out);
     }

我从代码(conn = DriverManager.getConnection(connectionURL))中获得异常:

`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:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.sid.WwdClientExample.main(WwdClientExample.java:57)
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)'

我已经在我的WEB-INF / lib文件夹中包含了derby jar文件。 我是derby的新手,我想尝试与derby建立连接。

感谢您的帮助。

0 个答案:

没有答案