I have an orion server using a datasource.
I want to connect to this datasource from outside the application but I'm having
problems.
I have created this program.
import java.util.*;
import java.sql.*;
import javax.naming.*;
import com.evermind.sql.*;
public class TestConnect
{
public TestConnect()
{
try
{
System.out.println ("Before IC");
InitialContext ic = new InitialContext();
System.out.println ("After IC");
OrionPooledDataSource ds =
(OrionPooledDataSource)ic.lookup("java:comp/env/external/DATASOURCE");
Connection c = ds.getConnection();
System.out.println ("After Connection, c is isClosed = " + new Boolean
(c.isClosed()).toString());
String query = "SELECT COUNT(*) FROM USERS";
PreparedStatement s = c.prepareStatement(query);
System.out.println ("After createStatement, s is null = " + new Boolean
(s==null).toString());
ResultSet rs = s.executeQuery ();
rs.next();
System.out.println ("User Count = " + rs.getString ("COUNT (*)"));
rs.close();
s.close();
c.close();
}
catch (SQLException ex)
{
System.out.println (ex.getMessage());
ex.printStackTrace();
}
catch (NamingException ex)
{
System.out.println (ex.getMessage());
}
}
public static void main (String[] args)
{
new TestConnect();
}
}
I have also set up the jndi.properties file
java.naming.factory.initial=com.evermind.server.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost/app
java.naming.security.principal=admin
java.naming.security.credentials=password
The program runs and i getting the following output and error.
Before IC
After IC
Exception in thread "main" java.lang.NullPointerException
at com.evermind.sql.OrionPooledDataSource.d7(JAX)
at com.evermind.sql.OrionPooledDataSource.d8(JAX)
at com.evermind.sql.OrionPooledDataSource.getConnection(JAX)
at TestConnect.<init>(TestConnect.java:17)
at TestConnect.main(TestConnect.java:45)
Has anyone got any ideas why i would be getting this error.
I have also tried different DataSource classes to see if you had to us a specific one
for remote connections. Still not luck.
Thanks Owen