Reputation: 1
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)
Upvotes: 0
Views: 1537
Reputation: 1091
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
Upvotes: 2
Reputation: 116
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
Upvotes: 0