关于executeBatch()
public int reply(BlogMsg msg, int fatherId) {// 创建数据库连接对象:
try{
//这里是与数据库的连接,并且确定是对的,然后:
Statement stmt = null;
ResultSet rs = null;
// try {
int maxid = 1;
String sql = "use blog select max(msg_ID) as maxid from blogmsg";
// 创建数据记录集对象:
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
maxid = rs.getInt(1) + 1;
}
// sql语句:
sql = "use blog insert into blogmsg(author,msg_content,"
+ "msg_date,is_origional,fathers_id,msg_replynum,browsed_times,"
+ "latest_replication_id) values('"
+ msg.getauthor()
+ "','"
+ msg.getmsg_content()
+ "','"
+ msg.getStrmsg_date()
+ "','1','"
+ fatherId
+ "','0','0','" + maxid + "')";
sql = new String(sql.getBytes("ISO8859-1"), "UTF-8");
stmt.addBatch(sql);
sql = "use blog update blogmsg set msg_replynum=msg_replynum+1,latest_replication_id='"
+ maxid + "' where msg_ID='" + fatherId + "'";
stmt.addBatch(sql);
// 执行sql语句:
stmt.executeBatch();
return 1;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
}
我想问一下,这段代码正确执行,就是正确的插入数据库然后更新相关信息,那它是应该返回1,但是我返回的好像是null,搞了几天了还是不知道为什么??????
重点看下红色部分,是不是有错。真是愁人呐。。。。