目前我有下面的代码,我试图从 Object 转换为 String 并且我得到一个异常错误。
将此 Object 数组转换为 String 数组以便它在我的 for 循环中工作的最佳方法是什么?或者有没有办法改变我的 for 循环来显示对象数组?
<%
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:/Users/rhysparker/Documents/workspace/Resource_Planner/WebContent/db/RESOURCE.SQLITE");
Statement stat = conn.createStatement();
ArrayList<ArrayList<String>> al = new ArrayList<ArrayList<String>>();
ResultSet rs = stat.executeQuery("select project_name from project;");
ResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
while (rs.next()) {
ArrayList<String> record = new ArrayList<String>();
for (int i = 1; i <= columns; i++) {
String value = rs.getString(i);
record.add(value);
}
al.add(record);
}
String[] testing = (String[])al.toArray();
for(int i=0;i<testing.length;i++)
{ %>
<option value="<%=testing[i]%>"><%=testing[i]%></option><%
}
rs.close();
conn.close();
%>