为什么我会收到此错误:
错误:java.sql.SQLException:ResultSet已关闭
来自此代码:
try{
ArrayList<String> longArray = new ArrayList<String>();
longArray.add("12345678912"); // All column in sqlite database are "text" so that's why I create String List
longArray.add("12345678911");
System.out.println(longArray);
String parameters = StringUtils.join(longArray.iterator(),",");
connection = sqliteConnection.dbConnector();
PreparedStatement pst=connection.prepareStatement("select columnA from TableUser where id in (?)");
pst.setString(1, parameters );
ResultSet rs = pst.executeQuery();
System.out.println(rs.getString("columnA")); // did not print anything, probably rs is empty
rs.close();
数据库详情:
我在数据库中有一个表TableUser
,其中有一列“id”为Text。
另一个问题:数据库12345678912
(TEXT)中的值是否与longArray.add("12345678912")
相同?
答案 0 :(得分:1)
You're missing an if(rs.next())
or while(rs.next())
after you retrieve the ResultSet
.
For your other question...yes, they're both Strings
aren't they?
Edit:
The problem was essentially trying to put multiple parameters into the IN
statement in a PreparedStatement
. See PreparedStatement IN Clause Alternatives