无法连接到嵌入式Derby数据库

时间:2014-07-17 14:44:20

标签: java netbeans derby javadb

我正在开发一个Java桌面应用程序,其中Java Embedded DB集成到NetBeans 7.2 IDE中  数据库是使用IDE创建的,现在它与前端是分开的。  现在我想将数据库连接到前端。当我尝试时,它给了我一个服务器未找到错误。下面是代码片段。

 static final String host   = "jdbc:derby:Wa_Poly";
 static final String uName  = "chief";
 static final String uPass  = "12345";    

连接的代码是:

    /* Connecting to the database */
    Connection  con = DriverManager.getConnection(host, uName, uPass);
    Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,  
    ResultSet.CONCUR_UPDATABLE);
    String sql = "SELECT * FROM APP.ALUMNUS";
    ResultSet rs = stmt2.executeQuery(sql); 
    populateIndex(rs, Scrollable);

这是给出的错误:

Jul 17, 2014 2:40:40 PM SearchEngine.SearchDB searchDatabase
SEVERE: null
java.sql.SQLException: Database 'Wa_Poly' not found.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at SearchEngine.Index.buildIndex(Index.java:118)
at SearchEngine.SearchDB.searchDatabase(SearchDB.java:96)
at wa_poly.MyJFrame.<init>(MyJFrame.java:47)
at wa_poly.MyJFrame$5.run(MyJFrame.java:292)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

Caused by: java.sql.SQLException: Database 'Wa_Poly' not found.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 

来源)     ......还有32个

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at SearchEngine.SearchDB.searchDatabase(SearchDB.java:105)
at wa_poly.MyJFrame.<init>(MyJFrame.java:47)
at wa_poly.MyJFrame$5.run(MyJFrame.java:292)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

欢迎任何解决问题的想法。

1 个答案:

答案 0 :(得分:1)

这还不够:

  

JDBC:德比:Wa_Poly

对于嵌入式连接必须类似于

  

jdbc:derby:C:/ Dokumente und   Einstellungen /管理员/的.netbeans-德比/ Wa_Poly

在这里看看我的答案 embedded Derby

修改

右键点击服务 - &gt; JavaDB - &gt;创建数据库

查看数据库文件夹的位置。

enter image description here