user6008715
user6008715

Reputation:

Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

I am new in java Jdbc I am going to write simple jdbc program `

   import java.sql.*;
   class jdbcDemo
     {
       public static void main(String[] args) throws Exception
        {
        Class.forName("oracle.jdbc.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","Scott","tiger");
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("select * from rk");
    while(rs.next())
    {
        System.out.println(rs.getInt(1)+"---"+rs.getString(2)+"---"+rs.getInt(3));
    }
    con.close();
    }
 }

after Successful compiling program At runtime i found following error

click here runtime error snapshot

I had used editplus editor and also i had created rk table in oracle 12c database

need help to fix issue

Upvotes: 0

Views: 6157

Answers (2)

Mehrdad Yami
Mehrdad Yami

Reputation: 1681

As you load class of oracle driver in your code :

Class.forName("oracle.jdbc.OracleDriver");

you just need to add oracle jdbc drivers(ojdbc6 or ojdbc7 ) into your project . you can download this jar file from thislink : JDBC DOWNLOAD LINK

Upvotes: 0

Rishi Goel
Rishi Goel

Reputation: 680

You need to provide the class for oracle driver. It will be in a jar which needs to be in class path. Since you are running from command prompt, this needs to be passed to run the class successfully.

Upvotes: 2

Related Questions