当前位置: 技术问答>java相关
为什么我不能更新数据表?
来源: 互联网 发布时间:2015-10-27
本文导语: 程序代码是这样的:(部分) Sql2 = "SELECT StoreAttributeCode FROM wktbl530 WHERE StoreCode='0101'"; Statement objStatement = objConnection.createStatement(); ResultSet rsWkTbl = objStatement.executeQuery(Sql2); if (rsWkTbl.first()) { rsWkTbl.updateString("Stor...
程序代码是这样的:(部分)
Sql2 = "SELECT StoreAttributeCode FROM wktbl530 WHERE StoreCode='0101'";
Statement objStatement = objConnection.createStatement();
ResultSet rsWkTbl = objStatement.executeQuery(Sql2);
if (rsWkTbl.first())
{
rsWkTbl.updateString("StoreAttributeCode","001");
}
错误是:Result Set not updateable. The query that generated this result set must select
only one table, and must select all primary keys from that table. See the JDBC 2
.1 API Specification, section 5.6 for more details.
我的wktbl530表没有设置主键的.数据库是mysql.
是不是没有设置主键,不能用rsWkTbl.updateString()?
Sql2 = "SELECT StoreAttributeCode FROM wktbl530 WHERE StoreCode='0101'";
Statement objStatement = objConnection.createStatement();
ResultSet rsWkTbl = objStatement.executeQuery(Sql2);
if (rsWkTbl.first())
{
rsWkTbl.updateString("StoreAttributeCode","001");
}
错误是:Result Set not updateable. The query that generated this result set must select
only one table, and must select all primary keys from that table. See the JDBC 2
.1 API Specification, section 5.6 for more details.
我的wktbl530表没有设置主键的.数据库是mysql.
是不是没有设置主键,不能用rsWkTbl.updateString()?
|
updateString是JDBC2的特性,是不是你那个数据库不支持这种做法,你写成一个sql语句,放在execute()里面执行应该就没问题了...
|
试一下其他方法来确定是不是updateString出错了。
|
updateString 换成executeUpdate()就没有问题了
|
要用参数。