0

enter image description here

 import java.sql.*;
 import java.io.*;

 public class OracleCon {


public static void main(String []args)throws ClassNotFoundException,SQLException,IOException
{

Class.forName("oracle.jdbc.OracleDriver");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe", "system", "123456789");
Statement st=con.createStatement();
String sql="insert into citylist values ('vijay','54222','110001')";
int r=st.executeUpdate(sql);

if(r>0)
{
    System.out.print("value inserted");
}
else
{
    System.out.print("value not inserted");
}
//ResultSet rs=st.executeQuery(sql);

//while(rs.next())
//  System.out.println(rs.getString(1)+""+rs.getString(2)+""+rs.getString(3));
con.close();


  }
}

I have installed oracle 11g and jdk 1.8 at windows 7

Exception in thread "main" java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver at java.net.URLClassLoader.findClass(Unknown source) at java.lang.ClassLoader.loadClass (Unknown source)

3
  • 1
    SO rule is put exception here, in form of text Commented Aug 14, 2017 at 11:00
  • Put the Oracle driver onto CLASSPATH... Commented Aug 14, 2017 at 11:03
  • FYI: the two images are the same Commented Aug 14, 2017 at 11:11

2 Answers 2

2

When you run your program in Command Line, you must include the jar file path in front of classpath parameter like this:

java OracleCon -classpath c:\somepath\ojdbc6.jar
Sign up to request clarification or add additional context in comments.

Comments

0

It could be that you are missing the actual jdbc driver for your Java version.

ojdbc6.jar from Oracle should do the trick for versions 6, 7 and 8.

Also don't forget to add the driver file to your classpath. If you are using Eclipse you can do that via right click on your project:

Properties > Java Build Path > Libraries

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.