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);
}
}
}
Asked
Active
Viewed 43 times
-2

OneCricketeer
- 179,855
- 19
- 132
- 245
-
2Did you add `mysql jar` to the classpath? – taurus05 Feb 08 '19 at 06:31
-
Looks like this code was copied directly for an assignment... You may want to take a minute to learn about dependency management and downloading external libraries – OneCricketeer Feb 08 '19 at 06:35
2 Answers
0
Please add mysql-connector.jar in your Classpath.
For more information:
http://javarevisited.blogspot.com/2012/03/jdbc-javalangclassnotfoundexception.html#ixzz2Ply4zLFF

Vinesh Shakelli
- 11
- 2
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