/**
* 新增书籍类型
* @param bookType 书籍类型对象
* @return 书籍类型id
* @throws SQLException
*/
public int addBookType(BookType bookType) throws SQLException{
Connection con = MyDBUtil.getConnection();
String sql = "insert into booktype(title,detail) values(?,?)";
PreparedStatement pst = con.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
pst.setString(1, bookType.getTitle());
pst.setString(2, bookType.getDetail());
pst.execute();
ResultSet rs = pst.getGeneratedKeys();
rs.next();
int id = rs.getInt("id");
rs.close();
pst.close();
con.close();
return id;
}
* 新增书籍类型
* @param bookType 书籍类型对象
* @return 书籍类型id
* @throws SQLException
*/
public int addBookType(BookType bookType) throws SQLException{
Connection con = MyDBUtil.getConnection();
String sql = "insert into booktype(title,detail) values(?,?)";
PreparedStatement pst = con.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
pst.setString(1, bookType.getTitle());
pst.setString(2, bookType.getDetail());
pst.execute();
ResultSet rs = pst.getGeneratedKeys();
rs.next();
int id = rs.getInt("id");
rs.close();
pst.close();
con.close();
return id;
}