每周总结

今天对对数据库的添加做了练习,对其中语句的意义进行了查询

public void add(student stu) {
Connection connection = DUBI_Student/* 连接数据库文件名 */.getConnection();
System.out.println(connection);
PreparedStatement preparedStatement = null;
try {
String sql = "insert into student(id,name,sex,classes,major) values (?,?,?,?,?)";// 执行语句
preparedStatement = connection.prepareStatement(sql);// 执行语句的转化
preparedStatement.setInt(1, stu.getId());
preparedStatement.setString(2, stu.getName());
preparedStatement.setString(3, stu.getSex());
preparedStatement.setString(4, stu.getClasses());
preparedStatement.setString(5, stu.getMajor());
preparedStatement.executeUpdate();
System.out.println("添加成功");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// DBUtil.close(resultSet);
DUBI_Student.close(preparedStatement);
DUBI_Student.close(connection);

}
}

posted @ 2020-11-05 20:23  不详·Christina  阅读(32)  评论(0)    收藏  举报