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!

Unable to establish connection

DevguySep 22 2010 — edited Oct 15 2014
import java.sql.*;
import java.util.*;

class AccountWithdrawl
{

public static void main(String[]args) throws Exception
{

Scanner s = new Scanner(System.in);
System.out.println("Enter the EMPNO :");
int EMPNO = s.nextInt();
System.out.println("Enter the Withdrawl Amount: Rs.");
float amount = s.nextFloat();
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:server","scott","tiger");
Statement st = con.createStatement();
int count = st.executeUpdate("UPDATE ACCOUNT SET BALANCE = BALANCE - " + amount + " WHERE EMPNO = " +EMPNO);
if(count!=0)
System.out.println(count + "Account updated Successfully");
}
}


The compilation of above program is successful,but when i run it i am getting the following errors

Exception in thread "main" 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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at AccountWithdrawl.main(AccountWithdrawl.java:15)

My oracle version is 11g Release 1..I set my system path as...C:\app\Sandy\product\11.1.0\db_1\jdbc\lib\ojdbc5.jar,even i tried with ojdbc6.jar..still it is showing the above stated error and even i set the path for classes12.jar...."C:\app\Sandy\product\11.1.0\db_1\oui\jlib\classes12.jar"..even that did not work out..

Thanks in advance for the person who solves my problem
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2010
Added on Sep 22 2010
6 comments
636 views