package com.myjdbc;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.Statement;
public class DeleteRecord {
DBConnection onecon = new DBConnection();
Connection con = null;
private PreparedStatement pstmt = null;
private Statement stmt = null;
public int deleteOneStudent(String sno) {
// TODO Auto-generated constructor stub
int count = -1;
con = onecon.getConnection();
try {
pstmt = con.prepareStatement("delete from student where sno=?");
pstmt.setString(1, sno);
count = pstmt.executeUpdate();
pstmt.close();
con.close();
} catch (SQLException e) {
// TODO: handle exception
System.out.println("数据库读异常"+e);
}
return count;
}
public static void main(String[] args){
DeleteRecord c = new DeleteRecord();
int count = c.deleteOneStudent("20190810");
System.out.print("数据表中"+count+"条记录被删除");
}
}
数据信息的删除
最新推荐文章于 2024-05-23 10:01:13 发布