JBuilder and JDBC

I have a class [b]XDatabase.java[/b]

which performs all database functions (DML and DDL)correctly. This is a chunk of code..

publicclass XDatabase

{

Connection con =null;

Statement stmt =null;

ResultSet rset =null;

//Constructor

public XDatabase()

{

}

//Get database connection

publicvoid connectDatabase(String driver,String ip,int port, String SID, String userName,

String password)

{

try

{

Class.forName(driver);

System.out.println("Connecting to the local database");

//Assembling connection String

String dbUrl ="jdbc:oracle:thin:@"+ip+":"+port+":"+SID;

con = DriverManager.getConnection(dbUrl,userName,password);

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

}

catch(Exception e)

{

System.out.println("Error in connection ");

e.printStackTrace();

}

}// End Constructor

Now when i create a project in JBuilder, and use the same fuction as above it gives me exceptions while loding the driver at line Class.forName(driver)

The exceptions are as under:

C:\JBuilder9\jdk1.4\bin\javaw -classpath"C:\cvsroot\ibill\itariff\gui\iTariff\classes;C:\JBuilder9\lib\jbcl.jar;C:\JBuilder9\lib\dx.jar;C:\JBuilder9\lib\beandt.jar;C:\JBuilder9\jdk1.4\jre\lib\rt.jar;C:\JBuilder9\jdk1.4\jre\lib\i18n.jar;C:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;C:\JBuilder9\jdk1.4\jre\lib\jsse.jar;C:\JBuilder9\jdk1.4\jre\lib\jce.jar;C:\JBuilder9\jdk1.4\jre\lib\charsets.jar;C:\JBuilder9\jdk1.4\jre\classes;C:\JBuilder9\jdk1.4\lib\tools.jar" itariff.XTariff

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

at java.net.URLClassLoader$1.run(URLClassLoader.java:198)

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

at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

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

at java.lang.Class.forName(Class.java:140)

at itariff.XChargeSch.btnAdd_actionPerformed(XChargeSch.java:208)

at itariff.XChargeSch_btnAdd_actionAdapter.actionPerformed(XChargeSch.java:248)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5134)

at java.awt.Component.processEvent(Component.java:4931)

at java.awt.Container.processEvent(Container.java:1566)

at java.awt.Component.dispatchEventImpl(Component.java:3639)

at java.awt.Container.dispatchEventImpl(Container.java:1623)

at java.awt.Component.dispatchEvent(Component.java:3480)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

at java.awt.Container.dispatchEventImpl(Container.java:1609)

at java.awt.Window.dispatchEventImpl(Window.java:1590)

at java.awt.Component.dispatchEvent(Component.java:3480)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Error in connection

Please I need a quick solution.

Regards

[5175 byte] By [ali_hammada] at [2007-11-26 15:19:47]
# 1
Will there be anybody who can help me out...:(I need some serious helpThanx
ali_hammada at 2007-7-8 11:46:30 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
The Oracle driver files are not in your classpath. This is a Java 101 issue same as any other ClassNotFound Exception.
cotton.ma at 2007-7-8 11:46:30 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
I have added this in my classpathC:\JBuilder9\lib\classes12.jarwhich is oracle driverAnother program which was not developed with JBuilder, which is a stand alone class is working fine with the same code and driverPlz help
ali_hammada at 2007-7-8 11:46:30 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Wdell your JBuilder classpath isn't configured correctly. You need a JBuilder forum.
cotton.ma at 2007-7-8 11:46:30 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Ohh thanx God , I've at last done it!!

In JBuilder go to Project > Project Properties > click the Required Libraries

Click Add > New >

Put anything in "Name" text box like Oracle Driver

Then click Add button and browse to the path of oracle driver like "classes12.jar " or "classes12.zip"(which are oracle jdbc drivers)

Then click OK, you will come back to the "Select one or more libraries" window.

The driver is added to JBuilder, now you have to add it in your project, so select "Oracle Driver" or whatever name you specified of driver.

Click OK button

And now run the program, it will run correctly

Wieeeeee...

ali_hammada at 2007-7-8 11:46:30 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...