如何将数据库查询结果放入列表<;字符串[]>;-JAVA
我想使用一种从数据库中提取id列表的方法。我成功地使用了列表字符串,但无法使用我真正需要获得的列表字符串[]。这是我的try语句:如何将数据库查询结果放入列表<;字符串[]>;-JAVA,java,database,Java,Database,我想使用一种从数据库中提取id列表的方法。我成功地使用了列表字符串,但无法使用我真正需要获得的列表字符串[]。这是我的try语句: try { connection = getJNDIConnection(connectionName); pstmt = connection.prepareStatement(sqlQuery); // set the input parameters pstmt.setLong(1, group
try {
connection = getJNDIConnection(connectionName);
pstmt = connection.prepareStatement(sqlQuery);
// set the input parameters
pstmt.setLong(1, groupId);
resultSet = pstmt.executeQuery();
if (resultSet.next()) {
result = new ArrayList<String[]>();
do {
Array resultStr = resultSet.getArray(1);
result.addAll(resultStr);//here is the problem
if (Constants.DEBUG_MODE.equals("true")) {
logger.debug("[{}] Get the customers list id from database GROUPS_CUSTOMERS table={}", methodName, result);
}
} while(resultSet.next());
}
}
试试看{
connection=getJNDIConnection(connectionName);
pstmt=connection.prepareStatement(sqlQuery);
//设置输入参数
pstmt.setLong(1,groupId);
resultSet=pstmt.executeQuery();
if(resultSet.next()){
结果=新的ArrayList();
做{
数组resultStr=resultSet.getArray(1);
result.addAll(resultStr);//问题出在这里
if(Constants.DEBUG_MODE.equals(“true”)){
debug(“[{}]从数据库组获取客户列表id_customers table={}”,methodName,result);
}
}while(resultSet.next());
}
}
Eclipse返回了这样一条消息:“类型列表中的addAll(Collection)方法不适用于参数(数组)”。
我能试试别的吗?
非常感谢。这是因为
Array
不是集合
接口的实现。您可以尝试以下操作:
String[] arr = (String[]) resultSet.getArray(1).getArray();
result.add(arr);
希望第一线的演员们能发挥作用。如果没有,则必须使用调试器找到需要强制转换到的实际类型。谢谢,但请尝试提供帮助?。。