int nownum=0,borrowed=0; //booksinfo表中的现有数量-1,借阅次数+1;
boolean bool=true;
try {
PreparedStatement prst2;
prst2 = con.prepareStatement("select nownum,borrowed from booksinfo where id=?"); [color=Red] //提示这行有错误!!!空指针异常.哪异常?[/color]
prst2.setString(1, book_id);
ResultSet rs2 = prst2.executeQuery();
if(rs2.next())
{
nownum=rs2.getInt(1);
borrowed=rs2.getInt(2);
if(nownum<=0)
{ //防止图书借没了还能借出
bool=false;
}
else
{
nownum--;
borrowed++;
}
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(bool)
{
try
{
PreparedStatement prst3;
prst3 = con.prepareStatement("update booksinfo set nownum="+nownum+",borrowed="+borrowed+" where id='"+book_id+"'");
PreparedStatement prst4 =
con.prepareStatement
("insert into borrowinfo (id,sno,tname,book_id,borrowedtime,returntime) values('"+id+"','"+sno+"','"+tname+"','"+book_id+"','"+obtime+"','"+returntime2+"'");