今天我在使用预编译语句发现了类似的错误。
Error Descript as blew:
[Microsoft][sqlServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
经测试发现,原来时查询的字段和从结果集中取的字段顺序不一致的原因。我的相关代码如下:
1、SQL语句如下:
select top 20 a.status as status,asset_no,asset_desc,a.location_pkID as location_pkID,c.location_desc as location_desc,a.dept_pkID as dept_pkID,depart_desc,ip_address,mac_address from asset a join department b on a.dept_pkID=b.pkID join location c on a.location_pkID=c.pkID where a.site_pkID =1 and a.pkID not in (Select top 0 pkID from Asset order by a.pkID DESC) ORDER BY a.pkID DESC
2、取结果的代码如下:
Asset asset=new Asset();
asset.setStatus(rs.getInt("status"));
asset.setAssetNo(rs.getString("asset_no"));
asset.setLocationPkID(rs.getInt("location_pkID"));
asset.setAssetDesc(rs.getString("asset_desc"));
asset.setLocationDesc(rs.getString("location_desc"));
asset.setDeptPkID(rs.getInt("dept_pkID"));
asset.setDepartDesc(rs.getString("depart_desc"));
asset.setIpAddress(rs.getString("ip_address"));
asset.setMacAddress(rs.getString("mac_address"));
如上的写法就会报上边的错误,解决的办法是,取结果集的顺序和查询字段的顺序一致。
改正后的代码如下:
Asset asset=new Asset(); asset.setStatus(rs.getInt("status")); asset.setAssetNo(rs.getString("asset_no")); asset.setAssetDesc(rs.getString("asset_desc")); asset.setLocationPkID(rs.getInt("location_pkID")); asset.setLocationDesc(rs.getString("location_desc")); asset.setDeptPkID(rs.getInt("dept_pkID")); asset.setDepartDesc(rs.getString("depart_desc")); asset.setIpAddress(rs.getString("ip_address")); asset.setMacAddress(rs.getString("mac_address"));
总结以上是内存溢出为你收集整理的关于预编译语句使用的注意事项全部内容,希望文章能够帮你解决关于预编译语句使用的注意事项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)