-2
package jdbc3;

import java.sql.*;    
import java.sql.DriverManager;

public class InsertPrepared {

    public static void main(String[] args) {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/people?autoReconnect=true&useSSL=false","root","manish13595");
            PreparedStatement stmt=con.prepareStatement("insert into epmloyes values(?,?)");
            stmt.setInt(1, 101);
            stmt.setString(2, "Ratan");
            int i=stmt.executeUpdate();
        //  ResultSet rs=stmt.executeQuery();
        //  System.out.println(rs.getString(1)+ " " +rs.getString(2));
            System.out.println(i+"records insert");
            PreparedStatement stmt1=con.prepareStatement("select * from emp");  
            ResultSet rs=stmt1.executeQuery();  
            while(rs.next()){  
            System.out.println(rs.getInt(1)+" "+rs.getString(2));  
            }  
            con.close();
        }catch(Exception e) {
            System.out.println(e);
        }    
    }    
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

2 Answers2

0

Please add mysql-connector.jar in your Classpath.

For more information:

http://javarevisited.blogspot.com/2012/03/jdbc-javalangclassnotfoundexception.html#ixzz2Ply4zLFF

0

If you have your dependency managment with maven simply add the dependency to mysql driver in your pom.xml:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.47</version>
</dependency>
JosemyAB
  • 387
  • 3
  • 9