-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepared.java
More file actions
41 lines (34 loc) · 1020 Bytes
/
prepared.java
File metadata and controls
41 lines (34 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.pak;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class prepared {
public static Connection getconnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
return conn;
}
catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
Connection conn = prepared.getconnection();
try{
PreparedStatement sql =conn.prepareStatement("insert into student values(?,?,?)");
PreparedStatement sql1=conn.prepareStatement("delete from student where values(?,?)");
sql.setInt(1,1);
sql.setString(2,"Anuj");
sql.setString(3,"Raval");
int i=sql.executeUpdate();
System.out.println(i+"Records inserted");
conn.close();
}
catch (SQLException e){
e.printStackTrace();
}
}
}