删除数据
package com.javakc.test1;
import com.javakc.db.Utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class testDelete {
public static void delete(int id) throws SQLException {
Connection connection = null;
try {
connection = Utils.getConnection();
String sql = "delete from user where id=?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, id);
int rows = preparedStatement.executeUpdate();
System.out.println(rows);
preparedStatement.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.close();
}
}
}
public static void main(String[] args) throws SQLException {
delete(5);
}
}