java连接mysql删除时老出现下面的问题,请大神帮忙看一下!!!
publicintdeleteStudent(Stringid){Connectioncon=null;PreparedStatementpstmt=null;intn=...
public int deleteStudent(String id){
Connection con = null;
PreparedStatement pstmt = null;
int n =0;
try {
con = DBUtil.getConnection();
String sql = "delete base_students where id=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, id);
n= pstmt.executeUpdate();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally{
DBUtil.close(con, pstmt, null);
}
return n;
public class Test {
public static void main(String[] args) {
us.deleteStudent("5");
}
}
出现的错误为:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id='5'' at line 1 展开
Connection con = null;
PreparedStatement pstmt = null;
int n =0;
try {
con = DBUtil.getConnection();
String sql = "delete base_students where id=?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, id);
n= pstmt.executeUpdate();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally{
DBUtil.close(con, pstmt, null);
}
return n;
public class Test {
public static void main(String[] args) {
us.deleteStudent("5");
}
}
出现的错误为:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id='5'' at line 1 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询