db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dibyendu Majumdar" <dibye...@mazumdar.demon.co.uk>
Subject Network Client
Date Thu, 09 Jun 2005 22:38:43 GMT
Should this fail?

package org.simplejta.tests.jta;

import java.sql.DriverManager;
import java.sql.SQLException;

import javax.sql.PooledConnection;

import org.apache.derby.jdbc.ClientConnectionPoolDataSource;

public class Temp {

    public static void main(String[] args) {
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            DriverManager.getConnection("jdbc:derby://localhost:1527/tca");
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            DriverManager.getConnection("jdbc:derby://localhost:1527/tca");

            ClientConnectionPoolDataSource ds = new
ClientConnectionPoolDataSource();
            ds.setDatabaseName("tca");
            ds.setServerName("localhost"); // host with listening network
                                           // server.
            ds.setPortNumber(1527); // port of listening network server.
            ds.setUser("app"); // Assign the user ID
            ds.setPassword("app"); // Assign the password
            PooledConnection con = ds.getPooledConnection(); // Create a
                                                             // Connection
                                                             // object

        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

The exception thrown is:

org.apache.derby.client.am.DisconnectException:
java.security.PrivilegedActionException : Error opening socket to server
localhost on port 1527 with message : null
 at org.apache.derby.client.net.NetAgent.<init>(NetAgent.java:113)
 at
org.apache.derby.client.net.NetConnection.newAgent_(NetConnection.java:920)
 at org.apache.derby.client.am.Connection.<init>(Connection.java:293)
 at org.apache.derby.client.net.NetConnection.<init>(NetConnection.java:180)
 at org.apache.derby.jdbc.ClientDriver.connect(ClientDriver.java:122)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at org.simplejta.tests.jta.Temp.main(Temp.java:27)

The problem seems to be caused because of following being called more than
one:

            Class.forName("org.apache.derby.jdbc.ClientDriver");
            DriverManager.getConnection("jdbc:derby://localhost:1527/tca");

Regards

Dibyendu



Mime
View raw message