469,304 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

Derby database on localhost

112 100+
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:

Expand|Select|Wrap|Line Numbers
  1. java.sql.SQLNonTransientConnectionException: Insufficient data while reading fro
  2. m the network - expected a minimum of 6 bytes and received only -1 bytes.  The c
  3. onnection has been terminated.
  4.         at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unkn
  5. own Source)
  6.         at org.apache.derby.client.am.SqlException.getSQLException(Unknown Sourc
  7. e)
  8.         at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
  9.         at java.sql.DriverManager.getConnection(DriverManager.java:582)
  10.         at java.sql.DriverManager.getConnection(DriverManager.java:207)
  11.         at DataBaseReader.createOnlineDB(DataBaseReader.java:142)
  12.         at ToTheGallows.main(ToTheGallows.java:31)
  13. Caused by: org.apache.derby.client.am.DisconnectException: Insufficient data whi
  14. le reading from the network - expected a minimum of 6 bytes and received only -1
  15.  bytes.  The connection has been terminated.
  16.         at org.apache.derby.client.net.Reply.fill(Unknown Source)
  17.         at org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(Unknown So
  18. urce)
  19.         at org.apache.derby.client.net.Reply.readDssHeader(Unknown Source)
  20.         at org.apache.derby.client.net.Reply.startSameIdChainParse(Unknown Sourc
  21. e)
  22.         at org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttr
  23. ibutes(Unknown Source)
  24.         at org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyE
  25. xchange(Unknown Source)
  26.         at org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyE
  27. xchange(Unknown Source)
  28.         at org.apache.derby.client.net.NetConnection.flowUSRIDONLconnect(Unknown
  29.  Source)
  30.         at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
  31.  
  32.         at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
  33.         at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
  34.         at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConne
  35. ction(Unknown Source)
  36.         ... 5 more
if you wouldnt mind taking a peek at my code here is the method where the magic happens:
Expand|Select|Wrap|Line Numbers
  1.     public static void createOnlineDB(String DBName)
  2.     {
  3.         try{
  4.               Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
  5.             Debug.println("class loaded.");
  6.             System.setProperty("derby.drda.startNetworkServer","true");
  7.             Debug.println("startNetworkServer property set true");
  8.             conn = DriverManager.getConnection("jdbc:derby://localhost:80/ttg/"+DBName+";create=true");
  9.             conn.commit();
  10.             conn.close();
  11.         }catch(Exception e){e.printStackTrace();}
  12.     }
that starts at line 135.
debug is basically system.out.println 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
Apr 14 '08 #1
14 8462
JosAH
11,448 Expert 8TB
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
Apr 15 '08 #2
drsmooth
112 100+
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:
Expand|Select|Wrap|Line Numbers
  1.     public static void createOnlineDB(String DBName)
  2.     {
  3.         try{
  4.             Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  5.             Debug.println("class loaded.");
  6.             System.setProperty("derby.drda.startNetworkServer","true");
  7.             Debug.println("startNetworkServer property set true");
  8.             conn = DriverManager.getConnection("jdbc:derby://localhost:80/ttg/"+DBName+";create=true");
  9.             conn.commit();
  10.             conn.close();
  11.         }catch(Exception e){e.printStackTrace();}
  12.     }
thanks
ken
Apr 15 '08 #3
drsmooth
112 100+
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...even 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
Apr 16 '08 #4
JosAH
11,448 Expert 8TB
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...even 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
Apr 17 '08 #5
drsmooth
112 100+
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.
Apr 17 '08 #6
pronerd
392 Expert 256MB
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?
Apr 17 '08 #7
drsmooth
112 100+
i tried adjusting the port, now i got this:
Expand|Select|Wrap|Line Numbers
  1. java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1026 with message Connection refused: connect.
  2.     at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
  3.     at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
  4.     at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
  5.     at java.sql.DriverManager.getConnection(DriverManager.java:582)
  6.     at java.sql.DriverManager.getConnection(DriverManager.java:207)
  7.     at DataBaseReader.createOnlineDB(DataBaseReader.java:142)
  8.     at ToTheGallows.main(ToTheGallows.java:30)
  9. Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1026 with message Connection refused: connect.
  10.     at org.apache.derby.client.net.NetAgent.<init>(Unknown Source)
  11.     at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
  12.     at org.apache.derby.client.am.Connection.<init>(Unknown Source)
  13.     at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
  14.     at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
  15.     at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
  16.     ... 5 more
  17. Caused by: java.net.ConnectException: Connection refused: connect
  18.     at java.net.PlainSocketImpl.socketConnect(Native Method)
  19.     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
  20.     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
  21.     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
  22.     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
  23.     at java.net.Socket.connect(Socket.java:519)
  24.     at java.net.Socket.connect(Socket.java:469)
  25.     at java.net.Socket.<init>(Socket.java:366)
  26.     at java.net.Socket.<init>(Socket.java:179)
  27.     at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:196)
  28.     at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)
  29.     at java.security.AccessController.doPrivileged(Native Method)
  30.     ... 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
Apr 17 '08 #8
drsmooth
112 100+
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:
Expand|Select|Wrap|Line Numbers
  1.     public static void createOnlineDB(String DBName)
  2.     {
  3.         try{
  4.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  5.             Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  6.             Debug.println("class loaded.");
  7.  
  8.             conn = DriverManager.getConnection("jdbc:mysql://192.168.2.3:80/ttg/"+DBName+";create=true");
  9.             conn.commit();
  10.             conn.close();
  11.         }catch(Exception e){e.printStackTrace();}
  12.     }
and the error:
Expand|Select|Wrap|Line Numbers
  1. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  2.  
  3. Last packet sent to the server was 0 ms ago.
  4.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  5.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  6.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  7.     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  8.     at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
  9.     at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
  10.     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
  11.     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
  12.     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
  13.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  14.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  15.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  16.     at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  17.     at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
  18.     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
  19.     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
  20.     at java.sql.DriverManager.getConnection(DriverManager.java:582)
  21.     at java.sql.DriverManager.getConnection(DriverManager.java:207)
  22.     at DataBaseReader.createOnlineDB(DataBaseReader.java:143)
  23.     at ToTheGallows.main(ToTheGallows.java:32)
  24. Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
this database stuff is a pain in the neck lol

thanks,
ken
Apr 19 '08 #9
JosAH
11,448 Expert 8TB
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
Apr 20 '08 #10
drsmooth
112 100+
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
Apr 20 '08 #11
JosAH
11,448 Expert 8TB
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
Apr 20 '08 #12
drsmooth
112 100+
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
Apr 20 '08 #13
drsmooth
112 100+
finally!! after many hours wsted to this ive gotten it to work!

thanks alot for all your help
Apr 20 '08 #14
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.
Nov 17 '14 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by peter | last post: by
reply views Thread by gaya3 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.