| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 972 人关注过本帖
标题:关于executeBatch()
只看楼主 加入收藏
随便来一记
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-11-12
收藏
 问题点数:0 回复次数:0 
关于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,搞了几天了还是不知道为什么??????
重点看下红色部分,是不是有错。真是愁人呐。。。。
搜索更多相关主题的帖子: executeBatch 数据库 blog sql int 
2008-04-24 12:25
快速回复:关于executeBatch()
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016412 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved