Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Connection problem: JDBC2+mysql+poolman

2 views
Skip to first unread message

Eric Berg

unread,
Jul 12, 2001, 2:39:05 AM7/12/01
to
Env:

Linux Mandrake 7.0
JDK 1.3.1
Poolman 2.0.4
mySQL 3.23.39
mm.mysql-2.0.1

I've got everything installed so that the PoolManSample works with 3
parameters (jndi). Wonderful. My datasource obviously works just fine.

Now, I've written a test class to make the datasource connection. The
code is virtually identical to the datasource sample code in
PoolManSample.java, but it doesn't work.

I'm using the same classpath as when I'm successfully running
PoolManSample, but getting this stacktrace -- the ERROR: line is
output from the caught exception in my code, and is directly from the
sample code:

# java LoadDriverjndi
ERROR: JNDI Exception Occurred. Is your JNDI resource available?

javax.naming.ServiceUnavailableException. Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested except
java.net.ConnectException: Connection refused
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
at java.net.Socket.<init>(Socket.java:273)
at java.net.Socket.<init>(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:25)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:120)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:91)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at LoadDriverjndi.main(LoadDriverjndi.java:26)

My code:

// Code Studio PoolMan Library
import com.codestudio.util.*;
import com.codestudio.sql.PoolMan;
import java.sql.*;
import java.io.*;
import java.util.*;
// The JDBC 2.0 Extension
import javax.sql.*;

// The JNDI package
import javax.naming.*;

public class LoadDriverjndi {
public static void main(String[] Args) {
ResultSet rs = null;
Statement Stmt = null;
String sql = "SELECT first_name from table_user";
String jndiName = "jndi-jobsdb";

try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
Connection con = null;

try {
con = ds.getConnection();
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = st.executeQuery(sql);
/*
I'll do something with the result set when I get one..
*/
}
catch (SQLException e) {
System.out.println("Couldn't get context or datasource.");
System.out.println("SQLException: " + e.getMessage());
System.out.println("SQLState: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
}
}
catch (javax.naming.NameNotFoundException nne) {
System.out.println("ERROR: No DataSource is registered under the name " +
jndiName + ", please check your poolman.props " +
" and deployment tool.\n");

// This is the exception that is caught....
} catch (javax.naming.NamingException nex) {
System.out.println("ERROR: JNDI Exception Occurred. " +
"Is your JNDI resource available?\n");
System.out.println(nex.getMessage());
nex.printStackTrace();
} catch (java.security.AccessControlException ae) {
System.out.println("ERROR: You cannot execute the DataSource example with " +
"the security permissions you are using. Try using the " +
"poolman.policy file: " +
"java -Djava.security.policy=/blah/poolman.policy.\n");
}
}
}

I've been banging on this for hours. Can't figure it out. Can
anybody shed any light on what my problem might be?

Thanks.

-Eric.

--
Eric D. Berg <eb...@nylug.org>
http://nylug.org/~eberg
Tel. 212-974-1041

0 new messages