String username = "root"; String password = "lch200276"; String url = "jdbc:mysql://localhost:3306/db1?serverTimezone=UTC"; Connection conn = DriverManager.getConnection(url, username, password); PreparedStatement pstmt = null; Scanner sc = new Scanner(System.in);

try { System.out.println("请输入要修改的员工的编号"); String id = sc.next(); System.out.println("请输入修改的工资"); String salary = sc.next();

pstmt = conn.prepareStatement("UPDATE employee SET salary = ? WHERE eno = ?");
pstmt.setString(1, salary);
pstmt.setString(2, id);

int rowsAffected = pstmt.executeUpdate();
if(rowsAffected > 0) {
    System.out.println("修改成功");
} else {
    System.out.println("修改失败");
}

} catch(SQLException e) { e.printStackTrace(); } finally { if(pstmt != null) { pstmt.close(); } conn.close();

String username = root; String password = lch200276; String url = jdbcmysqllocalhost3306db1serverTimezone=UTC; Connection conn = DriverManagergetConnectionurl username password;

原文地址: https://www.cveoy.top/t/topic/ha30 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录