Topic
3 replies Latest Post - ‏2009-10-29T16:01:29Z by Stan
balcerman
balcerman
3 Posts
ACCEPTED ANSWER

Pinned topic Problem with Derby Embedded Server

‏2009-10-29T10:10:08Z |
Hello,

I'm trying to launch Derby Embedded Server - Dervy version which you can use as both Embedded and Network Server.

The description is here:
http://db.apache.org/derby/papers/DerbyTut/ns_intro.html#Embedded+Server

The problem is that I apparently can't launch it properly, since still I am able to connect with it in one way at one time - with Apache Derby Embedded driver or with Apache Derby Client driver, but not with both of them at once.

I get the stack trace ('derbyEmbeddedServer' is my database name, 'C:\Program Files\Sun\JavaDB\bin\derbyEmbeddedServer' is where my database is created):

java.sql.SQLException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040, SQLERRMC: Failed to start database 'derbyEmbeddedServer', see the next exception for details.::SQLSTATE: XSDB6Another instance of Derby may have already booted the database C:\Program Files\Sun\JavaDB\bin\derbyEmbeddedServer.
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 net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.execute(OpenConnectionCommand.java:97)
at net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand$SheetHandler.run(ConnectToAliasCommand.java:280)
at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.derby.client.am.SqlException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040, SQLERRMC: Failed to start database 'derbyEmbeddedServer', see the next exception for details.::SQLSTATE: XSDB6Another instance of Derby may have already booted the database C:\Program Files\Sun\JavaDB\bin\derbyEmbeddedServer.
at org.apache.derby.client.am.Connection.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseRdbAccessFailed(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseAccessRdbError(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseACCRDBreply(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.readAccessDatabase(Unknown Source)
at org.apache.derby.client.net.NetConnection.readSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
... 6 more
Has anyone launched Derby Embedded Server successfully?
If so, may I ask for some steps on how to do that?
Updated on 2009-10-29T16:01:29Z at 2009-10-29T16:01:29Z by Stan
  • balcerman
    balcerman
    3 Posts
    ACCEPTED ANSWER

    Re: Problem with Derby Embedded Server

    ‏2009-10-29T12:08:23Z  in response to balcerman
    OK I did it :D
    the problem is that setting the property
    derby.drda.startNetworkServer=true

    doesnt work to me, but when I added the following lines to my application:

    import org.apache.derby.drda.NetworkServerControl;
    import java.net.InetAddress;
    NetworkServerControl server = new NetworkServerControl
    (InetAddress.getByName("localhost"),1527);
    server.start(null);
    the Derby started to work as embedded server (which means that it is started by the application that contains these lines above and stopped while this application disconnects from Derby) but additionally you can connect to it via the port 1527, as in Network Server case :)

    So the problem is solved to me.
  • balcerman
    balcerman
    3 Posts
    ACCEPTED ANSWER

    Re: Problem with Derby Embedded Server

    ‏2009-10-29T12:08:37Z  in response to balcerman
    OK I did it :D
    the problem is that setting the property
    derby.drda.startNetworkServer=true

    doesnt work to me, but when I added the following lines to my application:

    import org.apache.derby.drda.NetworkServerControl;
    import java.net.InetAddress;
    NetworkServerControl server = new NetworkServerControl
    (InetAddress.getByName("localhost"),1527);
    server.start(null);
    the Derby started to work as embedded server (which means that it is started by the application that contains these lines above and stopped while this application disconnects from Derby) but additionally you can connect to it via the port 1527, as in Network Server case :)

    So the problem is solved to me.
    • Stan
      Stan
      267 Posts
      ACCEPTED ANSWER

      Re: Problem with Derby Embedded Server

      ‏2009-10-29T16:01:29Z  in response to balcerman
      Glad you got this working. Without the exact sequence that was executed I can only speculate as to what may have happened originally.

      You wrote: the problem is that setting the property
      derby.drda.startNetworkServer=true ... doesnt work to me

      - This should start network server when the Derby driver is loaded (e.g. Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance()
      EXAMPLE:
      /*
      If you are running on JDK 1.6 or higher, then you do not
      need to invoke Class.forName(). In that environment, the
      EmbeddedDriver loads automatically.
      */
      Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
      Connection conn = DriverManager.getConnection(
      "jdbc:derby:sample");

      >> one thing that could have happened is that Network Server got started in a different JVM than you JDBC program (e.g. one of the IJ sessions loaded the driver first) or somehow was started in a different classLoader from the emedded driver (this can happen in App Server and IDE enivironments).

      Hope this helps you determine what might have happened - if not and you would like to post the code used and sequence of events leading to the problem I will take a look at it to see if perhaps a bug has been introduced to Derby.