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";
        Class.forName(dbdriver).newInstance();
// connection string where "192.168.10.125" is ip address of my server PC and "139" is port number of   //my server PC
 con = DriverManager.getConnection("jdbc:derby://192.168.10.125:139/C:\\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.

Dani AI

Generated

Most likely cause: the client is talking to a different service than Derby’s network listener (a protocol mismatch). That produces the “insufficient data” read because the remote endpoint sent something other than the Derby handshake and then closed the socket. In practical terms, using a Windows file‑sharing port or a non‑Derby service on the same port will produce exactly this symptom.

Quick checks to run now (server and client):

# on the server (Windows)
netstat -an | findstr LISTENING | findstr :1527

# from the client (PowerShell)
Test-NetConnection -ComputerName 192.168.10.125 -Port 1527

If the server isn’t listening on the port you expect, start the Derby Network Server (or re-start it using the documented launcher) and re-check. If a different service answers (for example SMB on port 139), change the server to use Derby’s listener port and/or change your client to the correct port. Also make sure the server machine’s firewall allows inbound TCP on that port and that the Java process running the Network Server has permission to create files in the target folder.

Connection-string and deployment notes tied to this thread: when you use the network (client/server) mode, the database path is interpreted on the server side — the client should normally supply a database name (or an absolute path as the server sees it). Best practice is to set derby.system.home on the server to a dedicated folder (not the root of C:) and use a URL that names the database on the server, e.g.:

jdbc:derby://server-host:1527/QuintexDB;create=true

Finally, ensure the Derby client jar and server are compatible and that the Network Server logs on the server show a clean startup. This addresses the port/protocol point mentioned by and should help isolate whether the problem is network/service selection, firewall/permissions, or a server-side configuration issue.

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 https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

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";

with:

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.