CodeAngel
CodeAngel

Reputation: 579

Unable to connect to Embedded Derby Database

I am developing a java desktop application with Java Embedded DB integrated into the NetBeans 7.2 IDE The database was created using the IDE and it is separate from the front end for now. Now I want to connect the database to the front end. When I try, it gives me a server not found error. below are codes snippets.

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

the code for the connection is :

    /* 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);

this is the error given:

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 

Source) ... 32 more

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)

any idea to solve the problem is welcomed.

Upvotes: 1

Views: 2038

Answers (1)

moskito-x
moskito-x

Reputation: 11968

this is not enough :

jdbc:derby:Wa_Poly

for a embedded connection must be something like

jdbc:derby:C:/Dokumente und Einstellungen/Administrator/.netbeans-derby/Wa_Poly

look at my answer here
embedded Derby

EDIT

Right click Services -> JavaDB -> create database

look where your database folder is.

enter image description here

Upvotes: 1

Related Questions