You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Mikael <mi...@telia.com> on 2008/06/17 13:24:55 UTC

Derby shutdown question

Hi !

Derby: 10.4.1.3

I run a Derby server like:
    private NetworkServerControl    server;
    server = new NetworkServerControl( InetAddress.getByName( "localhost"), 
port);
    server.start( null);

Later on I close all connections and shutdown the server like:
   server.shutdown();
   server = null;

And then I start the server again just like above, but this does not work, I 
can open a
connection but when I execute a query it fails with something like:

java.sql.SQLNonTransientConnectionException: Insufficient data while 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.am.SQLExceptionFactory40.getSQLException(Unknown 
Source)
        at org.apache.derby.client.am.SqlException.getSQLException(Unknown 
Source)
        at org.apache.derby.client.am.DatabaseMetaData.getTables(Unknown 
Source)

This was with a metadata.getTables() call but it is the same thing with any 
sql query.

Is there anything else I have to do to get the server to shutdown and 
restart correct ?

Mikael


Re: Derby shutdown question

Posted by Mikael <mi...@telia.com>.
I will give that a try, but it is probably my fault, when I call shutdown() 
on
the server the db.lck file is not deleted, so I guess se server is not 
shutting
down as it should and a not to wild guess would be that it is my fault.

(The db.lck file is deleted when my application ends normally).

----- Original Message ----- 
From: "Kathey Marsden" <km...@sbcglobal.net>
To: "Derby Discussion" <de...@db.apache.org>
Sent: Tuesday, June 17, 2008 2:44 PM
Subject: Re: Derby shutdown question


> Mikael wrote:
>> And then I start the server again just like above, but this does not
>> work, I can open a
>> connection but when I execute a query it fails with something like:
>>
>> java.sql.SQLNonTransientConnectionException: Insufficient data while
>> reading from the network - expected a minimum of 6 bytes and received
>> only -1 bytes. The connection has been terminated.
> I tried this and it seemed to work ok for me with 10.4.1.3.  Can you
> modify the attached program to show the failure?  Also you might want to
> look in derby.log to see if there is something that happenned server
> side that caused the problem.
>
> Kathey
>
>


--------------------------------------------------------------------------------


> import org.apache.derby.drda.NetworkServerControl;
> import java.sql.*;
> import java.io.PrintWriter;
> import java.net.InetAddress;
>
> public class RestartServer {
>
>    public static void main(String args[]) throws Exception
>    {
> int port = 1527;
> NetworkServerControl nsctrl = new NetworkServerControl( 
> InetAddress.getByName( "localhost"), port); ;
> startServer(nsctrl);
> connect();
>
> // bring down the server
> nsctrl.shutdown();
> startServer(nsctrl);
> connect();
>
>    }
>
>    public static void startServer(NetworkServerControl nsctrl)
> throws Exception {
> nsctrl.start(null);
> // ping until server comes up.
> for (int i = 0; i < 30; i++)
>     {
> try {
>     nsctrl.ping();
>     System.out.println("Server came up succssfully");
>     break;
> } catch (Exception e) {
>     if (i == 29)
> e.printStackTrace();
>     else
> Thread.sleep(5000);
> }
>        }
>
>    }
>
>    public static void connect() throws Exception {
>
> // check client connection is working ok.
> Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
> Connection conn = 
> DriverManager.getConnection("jdbc:derby://localhost:1527/testdb;create=true");
> Statement s = conn.createStatement();
> String sql = "select count(*) from sys.systables";
> System.out.print(sql + ":");
> ResultSet rs = s.executeQuery(sql);
> rs.next();
> System.out.println(rs.getString(1));
> rs.close();
> s.close();
> conn.close();
>
>    }
> }
> 


Re: Derby shutdown question

Posted by Mikael <mi...@telia.com>.
As usual it was my fault, my connection pool closed all open connections
but just after that it opened a new connection to write down a record to
the database just before shutdown() was called, and with one connection
still open shutdown() did not work as expected.

----- Original Message ----- 
From: "Kathey Marsden" <km...@sbcglobal.net>
To: "Derby Discussion" <de...@db.apache.org>
Sent: Tuesday, June 17, 2008 2:44 PM
Subject: Re: Derby shutdown question


> Mikael wrote:
>> And then I start the server again just like above, but this does not
>> work, I can open a
>> connection but when I execute a query it fails with something like:
>>
>> java.sql.SQLNonTransientConnectionException: Insufficient data while
>> reading from the network - expected a minimum of 6 bytes and received
>> only -1 bytes. The connection has been terminated.
> I tried this and it seemed to work ok for me with 10.4.1.3.  Can you
> modify the attached program to show the failure?  Also you might want to
> look in derby.log to see if there is something that happenned server
> side that caused the problem.
>
> Kathey
>
>


--------------------------------------------------------------------------------


> import org.apache.derby.drda.NetworkServerControl;
> import java.sql.*;
> import java.io.PrintWriter;
> import java.net.InetAddress;
>
> public class RestartServer {
>
>    public static void main(String args[]) throws Exception
>    {
> int port = 1527;
> NetworkServerControl nsctrl = new NetworkServerControl( 
> InetAddress.getByName( "localhost"), port); ;
> startServer(nsctrl);
> connect();
>
> // bring down the server
> nsctrl.shutdown();
> startServer(nsctrl);
> connect();
>
>    }
>
>    public static void startServer(NetworkServerControl nsctrl)
> throws Exception {
> nsctrl.start(null);
> // ping until server comes up.
> for (int i = 0; i < 30; i++)
>     {
> try {
>     nsctrl.ping();
>     System.out.println("Server came up succssfully");
>     break;
> } catch (Exception e) {
>     if (i == 29)
> e.printStackTrace();
>     else
> Thread.sleep(5000);
> }
>        }
>
>    }
>
>    public static void connect() throws Exception {
>
> // check client connection is working ok.
> Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
> Connection conn = 
> DriverManager.getConnection("jdbc:derby://localhost:1527/testdb;create=true");
> Statement s = conn.createStatement();
> String sql = "select count(*) from sys.systables";
> System.out.print(sql + ":");
> ResultSet rs = s.executeQuery(sql);
> rs.next();
> System.out.println(rs.getString(1));
> rs.close();
> s.close();
> conn.close();
>
>    }
> }
> 


Re: Derby shutdown question

Posted by Kathey Marsden <km...@sbcglobal.net>.
Mikael wrote:
> And then I start the server again just like above, but this does not 
> work, I can open a
> connection but when I execute a query it fails with something like:
>
> java.sql.SQLNonTransientConnectionException: Insufficient data while 
> reading from the network - expected a minimum of 6 bytes and received 
> only -1 bytes. The connection has been terminated.
I tried this and it seemed to work ok for me with 10.4.1.3.  Can you 
modify the attached program to show the failure?  Also you might want to 
look in derby.log to see if there is something that happenned server 
side that caused the problem.

Kathey