Hi Pranav,

If the database doesn't already exist, don't forget to include the 'create=true' property.

For example,
jdbc:derby:sampleDB;create=true
Further explained in the Derby documentation:
http://db.apache.org/derby/docs/10.2/ref/rrefattrib26867.html

Thomas

Pranav Aggarwal wrote:
Hi all,

I am new to Derby, just trying a small program which makes connection to derby DB.
Following program I have written:
import java.sql.*;
                                                                                                                       
class derby_connect
{
      void connect() throws Exception
      {
              String driver="org.apache.derby.jdbc.EmbeddedDriver";
              String dbName="mydb";
              String connectionURL="jdbc:derby:"+dbName;
                                                                                                                       
              Connection conn=null;
              try
              {
                      Class.forName(driver);
              }catch(java.lang.ClassNotFoundException e)
              {
                      e.printStackTrace();
              }
              try
              {
                      conn=DriverManager.getConnection(connectionURL);
                      System.out.println("Connection established!!!");
              }
              catch(Throwable e)
              {e.printStackTrace();}
              finally {conn.close();}
                                                                                                                       
      }//end of connect()
      public static void main(String args[]) throws Exception
      {
              derby_connect dc=new derby_connect();
              dc.connect();
      }
}//end of class
                                                                                                                       
The program resides in same directory where DB is residing. Now when I run, I get the following error:

$ java derby_connect
java.sql.SQLException: Failed to start database 'mydb', see the next exception for details.
      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.bootDatabase(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:582)
      at java.sql.DriverManager.getConnection(DriverManager.java:207)
      at derby_connect.connect(derby_connect.java:21)
      at derby_connect.main(derby_connect.java:32)
Caused by: java.sql.SQLException: Failed to start database 'mydb', see the next exception for details.
      at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
      at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
      ... 16 more
Exception in thread "main" java.lang.NullPointerException
      at derby_connect.connect(derby_connect.java:26)
      at derby_connect.main(derby_connect.java:32)
Can any one help me with this?   



Reply via email to