Now I am making my pos software client - server based software. I am using java derby as the database. On the local host I am running the program successfully. But on the remote server I face an exception. First I tell you, how I am connecting to the remote server below:

I connect my laptop to my pc through LAN Cable. I am using my laptop as client and my desktop PC as Server. On my Server I run the following command to start the Derby Server:

C:\Program Files (x86)\Java\jdk1.7.0_79\db\lib> java -jar derbyrun.jar start server

Above mentioned command starts the derby server on my desktop computer.

I am using following driver and connection string on my client laptop:

// code for driver
String dbdriver = "org.apache.derby.jdbc.ClientDriver";
// connection string where "" is ip address of my server PC and "139" is port number of   //my server PC
 con = DriverManager.getConnection("jdbc:derby://\\QuintexDB; create = true"); 

When I run the program, following Exception Occurres:

"java.sql.SQLNonTransientConnectionException: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 5 bytes. The connection has been terminated."

I am searching this problem on internet since last night but all in vane. I will be thank ful to you if you can guide me on this.

Recommended Answers

All 7 Replies

You are using Java 7 - no public support since 2015. You should be very worried about your security. Current Java is 13. So the first thing is to update all your installations before trying again.
Also that "classForDriver" thing was replaced years and years ago by DriverManager. see

Are you sure it's "received only 5 bytes"? Zero bytes is the usual message.

Yes James bro I am sure it is 5 bytes. And kindly tell me if I install java latest version, will it cause any problems with my current source code. As I am using java 7

Java compilers have an option to compile using the syntax of a previous version, but in any case if you have code that stops running after Java 7 then you need to uodate it anyway.

The 5 is interesting because it sugests you have contacted a running responding server (the normal message is 0 bytes, meaning no reply... the server is not running or otherwize inaccessible). maybe it's a version incompatability?

Ok james bro. I am also trying to using the new driver code as the link tells me which you gave.
I replaced the following code:

String dbdriver = "org.apache.derby.jdbc.ClientDriver";


String dbdriver = "org.apache.derby.jdbc.ClientDataSource";

And I could not understand with what I should replace the folloiwng line:

 con = DriverManager.getConnection("jdbc:derby://localhost:1527/C:\\QuintexDB; create = true"); 

I mean in the above line what shoud I write Instead of "DriverManager.getConnction"?

Not sure where you are going here...
You don't need the dbdriver string or the classForName (althugh for Java 7 who knows now?). DriverManager.getConnection will find and load the appropriate driver from the registered drivers.
Your getConnection parameter looks odd - the database name should be just a database name, not a file path.

James brother actually I wrote the program in such a way that , if database exists , then it connects the database other wise it creates database and then connects with it. I explicitly wants that the database should be created in the C Drive, whether it is local host or server machine. Because I also have a Backup and Restore feature in my software, which allows user to take Backup or restore the Data on a single click of button. The program works perfectly with my local host. But it only create problem when I run derby on server machine. And I run the derby by the command which I posted in first post. Derby server also starts successfully but , when I run my program , then the above mentioned exception occurs.

And in your previous reply you said that " may be its version incompatibility". Can you elaborate what type of version incompatability can it be? Because I am using same version of jdk and Derby on my client and server machine.
Thanks in advance.

commented: If you are running on old Java versions, few will be able to answer when things get weird. +0

^ like rproffitt said.

The normal way to specify where databases are stored on the server is by specifying a Java system property called derby.system.home on the server. It would be quite bizzare if simply starting a Derby server would allow a remote user to create files anywhere in the server's file system!

The "version incompatability" I mentioned can also refer to the fact that there is no guarantee of compatibility of Java 7 with any 2019 operating system.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.