Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC in eclipse

843859Nov 2 2005 — edited Nov 20 2014
Hi,

I'm a java developer, but i'm new to eclipse and JBoss. i tried using a sample JDBC code in eclipse, and this is the error i'm getting. any idea why this is happening? if someone knows what is happ around, please let me know...

thanks,

ng.

This is the program:

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

/**
* Example 3.2. The SimpleConnection class is a command line application that
* accepts the following command line: java SimpleConnection DRIVER URL UID
* PASSWORD If the URL fits the specified driver, it will then load the driver
* and get a connection.
*/
public class SimpleConnection {
static public void main(String args[]) {
Connection connection = null;

// Process the command line
if (args.length != 4) {
System.out.println("Syntax: java SimpleConnection "
+ "DRIVER URL UID PASSWORD");
return;
}
try { // load the driver
Class.forName(args[0]).newInstance();
} catch (Exception e) { // problem loading driver, class not exist?
e.printStackTrace();
return;
}
try {
connection = DriverManager.getConnection(args[1], args[2], args[3]);
System.out.println("Connection successful!");
// Do whatever queries or updates you want here!!!
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}



and the error i get is..

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 SimpleConnection.main(SimpleConnection.java:46)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2008
Added on Nov 2 2005
15 comments
514 views