热门栏目:  公务员继续教育  专业技术人员继续教育  工勤人员继续教育  路之遥博客

您的位置:首页>路之遥博客>JAVA

JDBC获得数据库自增长值

2014-05-01 10:23 浏览: 5

摘要: JDBC获得数据库自增长值...

String sqlStr = "insert into TIMU(ITEM_NAME,ITEM_CONTENT,ITEMTYPE_ID,USER_ID,COURSE_ID," +
    "ITEM_KEY,ITEM_SCORE,ITEM_ANSWER) values(" +
     "'" + itemName + "'," +
     "'" + content + "'," +
      typeId + "," +
      "'" + userId + "'," +
      "'" + courseId + "'," +
      "'" + itemKey + "'," +
      "'" + score + "'," +
      "'" + finalItemAns + "')";
  
  Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pstmt = null;
        int generateId = 0;
       
        try{
         conn = ConnCreator.getConnection();
         pstmt = conn.prepareStatement(sqlStr, Statement.RETURN_GENERATED_KEYS);
      pstmt.executeUpdate();
     
      rs = pstmt.getGeneratedKeys();
      if (rs.next()) {
       generateId = rs.getInt(1);
       LogHelper.log("新增习题信息成功,sql:" + sqlStr);
      } else{
       LogHelper.log("新增习题信息失败,sql:" + sqlStr);
      }
        }catch(Exception ex){
         
        }finally{
         try {
    rs.close();
    pstmt.close();
    conn.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
        }

你可能也喜欢:

最近更新

路之遥继续教育网,扫描加好友

讨论区最新话题

创新产品推荐

技术支持:常州路之遥软件有限公司 版权所有
备案号:苏ICP备09092440号