package utsc.java.jdbc.DBUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JDBCTest10 {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement ps = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/imooc","root","123456");
String sql = "update dept set dname = ? where deptno = ?";
ps = conn.prepareStatement(sql);
ps.setString(1,"x部门");
ps.setInt(2,30);
int count = ps.executeUpdate();
System.out.println(count);
ps.setString(1,"y部门");
ps.setInt(2,20);
count = ps.executeUpdate();
System.out.println(count);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}finally {
if (ps != null){
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}if (conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}