求助jsp问题,这段代码哪出错了
连接数据库
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article ");
ResultSetMetaData rsmd = rs.getMetaData();
int num = rsmd.getColumnCount(); //取得结果集中列数
int jb = num + 1;
String sql = "insert into article values(num, ?, ?, ?, ?, null, 0)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
pstmt.executeUpdate();
其中article表的第一列是id主键 十行( 1-10) 整型,sql server数据库的。请问这样jb怎么不是11呢,他总出主键不能重复的错
------解决方案--------------------
String sql = "insert into article values(num, ?, ?, ?, ?, null, 0)";
article表的第一列是id主键 对应的应该是num,当然是10,楼主应该用jb吧
String sql = "insert into article values(jb, ?, ?, ?, ?, null, 0)";
------解决方案--------------------如果你的id主键列是int型,你完全可以
SQL code
select max(id) from article
------解决方案--------------------
------解决方案--------------------
1)把SQL先用sqlplus 或pl/sql执行一下看有没有问题;
2)pstmt.setInt(1,id);
pstmt.setInt(2,rootid);
pstmt.setString(3,title);
pstmt.setString(4,cont);
改为setObject
3)把抛出的错误贴出来看一下
------解决方案--------------------