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();
        
    }
}

Reply via email to