读取代码如下: ResultSet rs=
s.executeQuery("select * " +
"from userProblemSolvedTable");
ResultSetMetaData metaData=rs.getMetaData();
int numOfColumns=metaData.getColumnCount(); //获得列数
Vector columnNames=new Vector();
// columnNames.addElement("User Name");
// columnNames.addElement("Problem AC");
// columnNames.addElement("Problem WA");
// columnNames.addElement("Problem PE");
for(int col=0;col<numOfColumns;col++){
columnNames.addElement(metaData.getColumnLabel(col+1));
}
Vector rows=new Vector();
while(rs.next()){
Vector newRow=new Vector();
for(int i=1;i<=metaData.getColumnCount();i++){
newRow.addElement(rs.getObject(i));
System.out.println(newRow.elementAt(i-1));
}
rows.addElement(newRow);
}
显示结果为:
userName problemAc problemWA problemPE
1 1 1
1 1 1
就是第一列userName无法显示,我打印出来是null的。不知道为什么?(数据库建表和显示结果的顺序一样)
s.executeQuery("select * " +
"from userProblemSolvedTable");
ResultSetMetaData metaData=rs.getMetaData();
int numOfColumns=metaData.getColumnCount(); //获得列数
Vector columnNames=new Vector();
// columnNames.addElement("User Name");
// columnNames.addElement("Problem AC");
// columnNames.addElement("Problem WA");
// columnNames.addElement("Problem PE");
for(int col=0;col<numOfColumns;col++){
columnNames.addElement(metaData.getColumnLabel(col+1));
}
Vector rows=new Vector();
while(rs.next()){
Vector newRow=new Vector();
for(int i=1;i<=metaData.getColumnCount();i++){
newRow.addElement(rs.getObject(i));
System.out.println(newRow.elementAt(i-1));
}
rows.addElement(newRow);
}
显示结果为:
userName problemAc problemWA problemPE
1 1 1
1 1 1
就是第一列userName无法显示,我打印出来是null的。不知道为什么?(数据库建表和显示结果的顺序一样)
// 這樣看看,你插入的數據和打印出來的是否一樣!
Object o = rs.getObject(i);
newRow.addElement(o);
System.out.println(o);
System.out.println(newRow.elementAt(i-1));
我的表中只有这些列:userName problemAC problemWA problemPE,建表的时候没有加自增的ID列的。
我觉得ID应该可有可无啊。
打印输出的结果一样的,但是插入的userName(即newRow.elementAt(0))一列打印的是null;