蓝
蓝色虾
Unregistered / Unconfirmed
GUEST, unregistred user!
我用jdbc-odbc联接access数据库
代码如下:
pstmt = con.prepareStatement(sql);
pstmt = con.prepareStatement("update news set"
+" subject=?,"
+" body=?,"
+" isonindex=?,"
+" office=?"
+" where newID=?");
pstmt.setString(1, news.getSubject());
pstmt.setString(2, news.getBody());
pstmt.setInt(3, news.getIsonindex());
pstmt.setString(4, news.getOffice());
pstmt.setString(5, news.getNewsID());
//---------------------------------
pstmt.executeUpdate();
执行这段代码,odbc报错,说参数应该为6个(该表中确实有六栏),难道非要全部更新才行吗?
我改换以下代码却得以通过:
String sql="update news set subject='"+news.getSubject()+"',body='"+news.getBody()+"',isonindex="+news.getIsonindex()+",office='"+news.getOffice()+"' where newsID='"+news.getNewsID()+"'";
pstmt = con.prepareStatement(sql);
pstmt.executeUpdate();
这里只更新了五栏数据,却能够通过
请问这是为何?我该怎么做才能依靠设置参数更新五栏数据?
代码如下:
pstmt = con.prepareStatement(sql);
pstmt = con.prepareStatement("update news set"
+" subject=?,"
+" body=?,"
+" isonindex=?,"
+" office=?"
+" where newID=?");
pstmt.setString(1, news.getSubject());
pstmt.setString(2, news.getBody());
pstmt.setInt(3, news.getIsonindex());
pstmt.setString(4, news.getOffice());
pstmt.setString(5, news.getNewsID());
//---------------------------------
pstmt.executeUpdate();
执行这段代码,odbc报错,说参数应该为6个(该表中确实有六栏),难道非要全部更新才行吗?
我改换以下代码却得以通过:
String sql="update news set subject='"+news.getSubject()+"',body='"+news.getBody()+"',isonindex="+news.getIsonindex()+",office='"+news.getOffice()+"' where newsID='"+news.getNewsID()+"'";
pstmt = con.prepareStatement(sql);
pstmt.executeUpdate();
这里只更新了五栏数据,却能够通过
请问这是为何?我该怎么做才能依靠设置参数更新五栏数据?