2014-07-17 97 views
0

我正在開發一個集成到NetBeans 7.2 IDE中的Java嵌入式數據庫的Java桌面應用程序 該數據庫是使用IDE創建的,目前它與前端分離。 現在我想將數據庫連接到前端。當我嘗試時,它給了我一個服務器找不到錯誤。以下是代碼片段。無法連接到嵌入式Derby數據庫

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

這是不夠的:

的jdbc:德比:Wa_Poly

的嵌入式連接必須是這樣的

的jdbc:德比:C:/文件UND Einstellungen/Administrator/.netbeans-derby/Wa_Poly

看看我的答案在這裏
embedded Derby

編輯

右鍵單擊服務 - > JavaDB之外 - >創建數據庫

看看您的數據庫文件夾。

enter image description here

+0

感謝您的回覆。我檢查了這個位置上的netbeans'C:\ Users \ Faisal \ .netbeans-derby'。但沒有找到數據庫。從屬性窗口看到的數據庫URL也是'jdbc:derby:Wa_​​Poly ;; create = true'。看起來像數據庫是missing.Any建議。 – CodeAngel

+0

按照編輯的建議,但仍然得到錯誤。看起來NetBeans在不同的位置創建數據庫。但不在.NetBeans文件夾中 – CodeAngel

+0

@CodeAngel:用Netbeans創建一個新的數據庫。如何看,看上面。並搜索您的系統搜索該文件。 –

相關問題