我有一个嵌套在 for 循环内的 while 循环内创建的字符串数组。这与在 Derby 中从一列字符串创建一个数组有关,但为了简单起见,我将省略一些内容。
我没有提供完整代码的原因是问题非常具体。我的数据库、结果集、语句或查询没有任何问题。它只是访问两个循环之外的数组。
//in the class,
private int rowCount; //Count of the rows in my column of strings
public String stringArray[];
//in the method I am using
public void myMethod() {
rowCount = 4; //In my code it actually counts it, lets say its four though.
stringArray = new stringArray[rowCount]; //set
for (int i = 0; i < rowCount; i++) {
while (rs.next()/*rs is simply a result set of a statement executeQuery to select the correct table*/)
{
stringArray[i] = rs.getString(2); //2 is the column number in the table
}
}
//Need to access stringArray here. When I try to print out values, it always prints out as null.
}
谢谢!