DriverManager.getConnection NullPointerException [message #92640] |
Tue, 02 November 2004 11:18 |
Bobman
Messages: 2 Registered: November 2004
|
Junior Member |
|
|
I am writing an applet that inserts data to an oracle database. it works fine on the oracle server, by running main() or using applet viewer. However, when I run remotely, I get a NullPointerException when I try to get a connection.
Here is my code:
/////////////////////////////////////////////////////////
.......
System.out.print("Registering driver...rn");
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
}
catch(java.sql.SQLException e)
{
System.out.print("register driver: Exception: " + e.getMessage()+"rn");
}
System.out.print("Loading driver...rn");
try { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); }
catch(java.lang.ClassNotFoundException m)
{
System.out.print("class for name: Exception class not found: " + m.getMessage()+"rn");
}
catch(java.lang.InstantiationException m)
{
System.out.print("Instantiation Exception: " + m.getMessage()+"rn");
}
catch(java.lang.IllegalAccessException m)
{
System.out.print("Illegal Access: " + m.getMessage()+"rn");
}
System.out.print("Creating connection... rn");
try {
conn = DriverManager.getConnection(url);
System.out.print("Connected to " + getlblSvrName().getText() + ".rn");
getlblConStatus().setText("Connected to " + getlblSvrName().getText() + ".");
getButton6().setEnabled(true);
getButton2().setEnabled(true);
getButton5().setEnabled(false);
connected = true;
getlblConnTime().setText(myDateTime);
}
catch (Exception x) {
getlblErrStatus().setText("DriverManager.getConnection:" + x.getMessage());
System.out.print(url + ": no connection!rn");
x.printStackTrace();
getlblConStatus().setText("Not Connected.");
connected = false;
}
......
/////////////////////////////////////////////////////////////
Here is the print out and stack trace:
Registering driver...
Loading driver...
Creating connection...
jdbc:oracle:thin:scott/tiger@IQUEST_BOB:1521:IQORACLE: no connection!
java.lang.NullPointerException at oracle.jdbc.driver.OracleDriver.connectOracleDriver.java:342)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
...
/////////////////////////////////////////////////////////////////
ClassPath:
.;C:oracleora92jdbclibclasses12.jar;C:oracleora92jdbclibojdbc14.jar;
ANY HELP WOULD RECEIVE MY UPTMOST APPRECIATION AND UNDYING SUPPORT!! :)
Bobman
|
|
|
Re: DriverManager.getConnection NullPointerException [message #92646 is a reply to message #92640] |
Fri, 05 November 2004 14:37 |
Praveen
Messages: 57 Registered: November 2001
|
Member |
|
|
Bob, it basically looks like a security issue. Applets have the restriction that they can access the database from the server they originate from. Obviously when you ran the applet locally from the Oracle server it ran, but when you ran remotely it failed. You need to build a certificate for it and then run it.
Hope this helps
|
|
|