-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJDBC.java
More file actions
29 lines (23 loc) · 769 Bytes
/
JDBC.java
File metadata and controls
29 lines (23 loc) · 769 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
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
public class JDBC {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc230", "root", "root");
PreparedStatement pstmt = con.prepareStatement("insert into employee (id,name,salary) values(?,?,?)");
pstmt.setInt(1, 101);
pstmt.setString(2, "KIM");
pstmt.setDouble(3, 9999);
int recCount = pstmt.executeUpdate();
if (recCount > 0) {
System.out.println("Added...");
} else {
System.out.println("Not Added...");
}
pstmt.close();
con.close();
}
}