Derby database on localhost

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsmooth
    New Member
    • Oct 2007
    • 112

    Derby database on localhost

    I hope you are all ok with the frequency of this question following my last, im struggling alot with this database stuff. and i really appreciate all the help from this forum, many a time you have saved my computer from a trip out my window lol.

    now im trying to create a derby database at runtime in my java code...ive created and used databases on the hard drive, but now im trying to move toward the net and started with the localhost.

    im getting this error consistanlty at runtime:

    Code:
    [I]java.sql.SQLNonTransientConnectionException: Insufficient data while reading fro
    m the network - expected a minimum of 6 bytes and received only -1 bytes.  The c
    onnection has been terminated.
            at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unkn
    own Source)
            at org.apache.derby.client.am.SqlException.getSQLException(Unknown Sourc
    e)
            at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:207)
            at DataBaseReader.createOnlineDB(DataBaseReader.java:142)
            at ToTheGallows.main(ToTheGallows.java:31)
    Caused by: org.apache.derby.client.am.DisconnectException: Insufficient data whi
    le reading from the network - expected a minimum of 6 bytes and received only -1
     bytes.  The connection has been terminated.
            at org.apache.derby.client.net.Reply.fill(Unknown Source)
            at org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(Unknown So
    urce)
            at org.apache.derby.client.net.Reply.readDssHeader(Unknown Source)
            at org.apache.derby.client.net.Reply.startSameIdChainParse(Unknown Sourc
    e)
            at org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttr
    ibutes(Unknown Source)
            at org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyE
    xchange(Unknown Source)
            at org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyE
    xchange(Unknown Source)
            at org.apache.derby.client.net.NetConnection.flowUSRIDONLconnect(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.newNetConne
    ction(Unknown Source)
            ... 5 more[/I]
    if you wouldnt mind taking a peek at my code here is the method where the magic happens:
    [CODE=cpp]
    public static void createOnlineDB( String DBName)
    {
    try{
    Class.forName(" org.apache.derb y.jdbc.Embedded Driver").newIns tance();
    Debug.println(" class loaded.");
    System.setPrope rty("derby.drda .startNetworkSe rver","true");
    Debug.println(" startNetworkSer ver property set true");
    conn = DriverManager.g etConnection("j dbc:derby://localhost:80/ttg/"+DBName+";crea te=true");
    conn.commit();
    conn.close();
    }catch(Exceptio n e){e.printStack Trace();}
    }[/CODE]

    that starts at line 135.
    debug is basically system.out.prin tln with an on/off switch. i coded it so i could quickly shut off unsighlty things when showing my friends the work so far...

    i really appreciate any help,
    thanks,
    ken
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You're using the wrong driver, don't use the EmbeddedDriver but use the ClientDriver.
    See the 'getting started' manual 'activity 4' for a detailed explanation.

    kind regards,

    Jos

    Comment

    • drsmooth
      New Member
      • Oct 2007
      • 112

      #3
      Originally posted by JosAH
      You're using the wrong driver, don't use the EmbeddedDriver but use the ClientDriver.
      See the 'getting started' manual 'activity 4' for a detailed explanation.

      kind regards,

      Jos
      right...that was actually a mistake, i changed it on my code in referce to some crazy example i saw online, this is the updated code, still with the same problem:
      [CODE=cpp]
      public static void createOnlineDB( String DBName)
      {
      try{
      Class.forName(" org.apache.derb y.jdbc.ClientDr iver").newInsta nce();
      Debug.println(" class loaded.");
      System.setPrope rty("derby.drda .startNetworkSe rver","true");
      Debug.println(" startNetworkSer ver property set true");
      conn = DriverManager.g etConnection("j dbc:derby://localhost:80/ttg/"+DBName+";crea te=true");
      conn.commit();
      conn.close();
      }catch(Exceptio n e){e.printStack Trace();}
      }[/CODE]

      thanks
      ken

      Comment

      • drsmooth
        New Member
        • Oct 2007
        • 112

        #4
        i read the manual activity 4, checked the example code against mine, and they seem to line up, is there something else that could be wrong? ive been getting quite frustrated with these databases, unfourtunately, they are quite pivotal to handling data...lol...ev en an explanation of what that error means may help, i tried google, but nothing came up but and old mailng list post with no response.


        thanks,
        ken

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by drsmooth
          i read the manual activity 4, checked the example code against mine, and they seem to line up, is there something else that could be wrong? ive been getting quite frustrated with these databases, unfourtunately, they are quite pivotal to handling data...lol...ev en an explanation of what that error means may help, i tried google, but nothing came up but and old mailng list post with no response.


          thanks,
          ken
          The error message is simple: you don't have a connection with the server. Have
          you actually started a server? I'll check the documentation when I have some time.

          kind regards,

          Jos

          Comment

          • drsmooth
            New Member
            • Oct 2007
            • 112

            #6
            Originally posted by JosAH
            The error message is simple: you don't have a connection with the server. Have
            you actually started a server? I'll check the documentation when I have some time.

            kind regards,

            Jos
            i have a localhost server set up on my computer already, im not really sure how it works, but it does as far as i know.

            Comment

            • pronerd
              Recognized Expert Contributor
              • Nov 2006
              • 392

              #7
              I have not worked with Derby so I maybe off base here. I noticed you are running it on port 80. That port is a reserved port for web servers. So using that port can cause two problems.

              First if you have a web server running too it will conflict with the database.

              Second most OS's now require that you have admin(root) privileges to run services on reserved ports. So if the account that the Derby service is running on maybe there is a reason for this.

              I would try running it on port 1025 or higher. Also have you checked the log files to make sure that Derby is successfully starting?

              Comment

              • drsmooth
                New Member
                • Oct 2007
                • 112

                #8
                i tried adjusting the port, now i got this:
                Code:
                java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1026 with message Connection refused: connect.
                    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 java.sql.DriverManager.getConnection(DriverManager.java:582)
                    at java.sql.DriverManager.getConnection(DriverManager.java:207)
                    at DataBaseReader.createOnlineDB(DataBaseReader.java:142)
                    at ToTheGallows.main(ToTheGallows.java:30)
                Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1026 with message Connection refused: connect.
                    at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
                    at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
                    at org.apache.derby.client.am.Connection.<init>(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)
                    ... 5 more
                Caused by: java.net.ConnectException: Connection refused: connect
                    at java.net.PlainSocketImpl.socketConnect(Native Method)
                    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
                    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
                    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
                    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
                    at java.net.Socket.connect(Socket.java:519)
                    at java.net.Socket.connect(Socket.java:469)
                    at java.net.Socket.<init>(Socket.java:366)
                    at java.net.Socket.<init>(Socket.java:179)
                    at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:196)
                    at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)
                    at java.security.AccessController.doPrivileged(Native Method)
                    ... 11 more
                the localhost is set up to lsten on port 80, my dad used it for something else before, im not really too sure on how to work with that...

                thanks
                ken

                Comment

                • drsmooth
                  New Member
                  • Oct 2007
                  • 112

                  #9
                  could the fact that i have apache web server installed in the localhost effect it? i switched over and now im trying to make a mysql database using the mysql conntector/j and im getting a communications link failure...

                  here is my new code:
                  [CODE=java] public static void createOnlineDB( String DBName)
                  {
                  try{
                  Class.forName(" com.mysql.jdbc. Driver").newIns tance();
                  Class.forName(" org.gjt.mm.mysq l.Driver").newI nstance();
                  Debug.println(" class loaded.");

                  conn = DriverManager.g etConnection("j dbc:mysql://192.168.2.3:80/ttg/"+DBName+";crea te=true");
                  conn.commit();
                  conn.close();
                  }catch(Exceptio n e){e.printStack Trace();}
                  }[/CODE]

                  and the error:
                  Code:
                  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
                  
                  Last packet sent to the server was 0 ms ago.
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                      at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
                      at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
                      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
                      at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
                      at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                      at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
                      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
                      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
                      at java.sql.DriverManager.getConnection(DriverManager.java:582)
                      at java.sql.DriverManager.getConnection(DriverManager.java:207)
                      at DataBaseReader.createOnlineDB(DataBaseReader.java:143)
                      at ToTheGallows.main(ToTheGallows.java:32)
                  Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
                  this database stuff is a pain in the neck lol

                  thanks,
                  ken

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by drsmooth
                    i switched over and now im trying to make a mysql database using the mysql conntector/j
                    If you wildly switch over to another DBMS if a previous DBMS doesn't work think
                    of it: umpty of people are working succesfully with that previous DBMS. How come?
                    I don't think it's the DBMS to blaim here; a bit more reading could've done the
                    job. Now you have to start reading all the documentation for your new DBMS.

                    kind regards,

                    Jos

                    Comment

                    • drsmooth
                      New Member
                      • Oct 2007
                      • 112

                      #11
                      well i made the desicion to switch as more of a convience thing, i wanted to be able to acess the database not just from derby but other internet type apps e.g php and stuff like that...bottom line, neither want to work for me lol

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Originally posted by drsmooth
                        well i made the desicion to switch as more of a convience thing, i wanted to be able to acess the database not just from derby but other internet type apps e.g php and stuff like that...bottom line, neither want to work for me lol
                        Note that we're not living in an ideal world, i.e. after you have created a database
                        with software package X (e.g. Derby), you can't access your data with another
                        software package Y (e.g. MySQL, DB/2, Oracle, you name them).

                        kind regards,

                        Jos

                        Comment

                        • drsmooth
                          New Member
                          • Oct 2007
                          • 112

                          #13
                          Originally posted by JosAH
                          Note that we're not living in an ideal world, i.e. after you have created a database
                          with software package X (e.g. Derby), you can't access your data with another
                          software package Y (e.g. MySQL, DB/2, Oracle, you name them).

                          kind regards,

                          Jos
                          right...thats why i switched over to using mysql

                          Comment

                          • drsmooth
                            New Member
                            • Oct 2007
                            • 112

                            #14
                            finally!! after many hours wsted to this ive gotten it to work!

                            thanks alot for all your help

                            Comment

                            • kosurusekhar
                              New Member
                              • Nov 2014
                              • 1

                              #15
                              Hi, Are you using Derby stored procedure with user defined types as parameter(s)?, if this is the case the jar version using from derby is older, From which application you called this procedure?

                              I faced this error with my Derby network server frequently.

                              You can keep same jar file in you application as well and derby while booting up will solve this problem.

                              Comment

                              Working...