JDBC之修改数据
public static void main(String[] args){
String lastname = JOptionPane.showInputDialog("请输入lastname:");
String firstname= JOptionPane.showInputDialog("请输入firstname:");
String sid= JOptionPane.showInputDialog("请输入id:");
int id = Integer.parseInt(sid);
try{
Class.forName("com.mysql.jdbc.Driver");
Driver d = new Driver();
DriverManager,registerDriver(d);
Connection conn = DriverManger.getConneection();
String sql = "update user1 set firstname = ?, lastName = ? where id =?"
PrepareStament ps = conn.prepareStament(sql);
ps.setOdject(1,firstname);
ps.setOdject(2,lastname);
ps.setOdject(1,id);
int result = ps.excecuteUpdate();
if(result > 0){
JOptionPane.showMessageDialog(null,"修改成功");
}
}catch(Exception e){
e.printStackTrace()
}
}