数据库下标问题
ps=dbc.getConnection().prepareStatement(sql);
ResultSet rs=ps.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
int num=rsmd.getColumnCount();
String row[];
while(rs.next()){
row=new String[]{};
for(int i=1;i<num+1;i++){
row[i]=rs.getString(i);
}
java.lang.ArrayIndexOutOfBoundsException: 1
at com.Member.MemberDAOIm.Selectall(MemberDAOIm.java:50) 我把i=0还是错? 怎么改
at com.Member.MemberDAOIm.main(MemberDAOIm.java:71)
[Ljava.lang.String;@1ff0dde
------解决方案--------------------
row=new String[]{};你有分配数组大小吗?不错才怪,去用集合吧,数组不现实的东西
------解决方案--------------------
Java code
ps=dbc.getConnection().prepareStatement(sql);
ResultSet rs=ps.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
int num=rsmd.getColumnCount();
List<List<String> > row= new ArrayList<List<String> >();//String row[];
while(rs.next()){
row.add(new ArrayList<String>());//row=new String[]{};
for(int i=1;i<num+1;i++){
row.get(i-1).add(rs.getString(i));
}