JDBC with Applet

Hi All,

My program uses Applet with JDBC. Everything in the program seems to be fine, but the error displayed does not give me a clue of where i'm going wrong. This is the error...

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at Applet1.connectToDB(Applet1.java:60)

at Applet1.access$0(Applet1.java:56)

at Applet1$1.actionPerformed(Applet1.java:44)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

and the func to establish the connectivity is as given here..

private void connectToDB(ActionEvent e)

{

try { // load the driver

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

} catch (Exception e1) { // problem loading driver, class not exist?

e1.printStackTrace();

return;

}

try {

//connection = DriverManager.getConnection();

con = DriverManager.getConnection("jdbc:oracle:thin:@my.com","nit","nit");

System.out.println("Connection successful!");

empValues.setText("Connected to the Database.Fetching Values from DEPT Tables.\n");

fetchValues();

} catch (SQLException ex){

System.out.println("Connection Error = " + ex.toString());

}

}

please let me know where i'm going wrong....

thanks,

ng

[3321 byte] By [cdsnitia] at [2007-10-2 6:31:17]
# 1
Perhaps you need to specify your port number?
anitakrisha at 2007-7-16 13:33:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Could you please let me know where n how to specify the port number?Thanks,ng.
cdsnitia at 2007-7-16 13:33:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

The problem is not with the port number. The driver class is not found in your case. You need to have the driver class in the classpath. I am not sure how this is done for applets. You could check the applet tutorial for that.

But, as I am thinking about the problem, if your applet is directly executing JDBC, you will need to include the driver jar with the applet. This will make the applet bulkier and slower to download since the applet is downloaded on the client side. What you should do is use a server-side component, a servlet prefereably, which will manage the database calls and communicate with the applet. This will eliminate the need for including the driver jar with the applet.

aniseeda at 2007-7-16 13:33:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...