0

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

1
  • 2
    did you add oracle driver to the classpath? Commented Aug 9, 2017 at 4:21

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

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