0

我用java编写了这段代码,有两个sql查询,按列不同,但bot显示相同的输出:public static void main(String args[]) throws SQLException{

connectDB();
java.sql.Statement st1= con1.createStatement();
java.sql.Statement st2= con2.createStatement();

String query1="select * from entries order by entries.name ;";
System.out.println(query1);

ResultSet rst1=st1.executeQuery(query1);
while(rst1.next()){
    System.out.println(rst1.getString(1)+" "+rst1.getString(2));

}
st1.close();con1.close();

String query2="select * from entries order by entries.number ;";
System.out.println(query2);

ResultSet rst2=st2.executeQuery(query1);
while(rst2.next()){
    System.out.println(rst2.getString(1)+" "+rst2.getString(2));

}

输出如下:

select * from entries order by entries.name ;
Smith 40
Taylor 46
Winland 44
select * from entries order by entries.number ;
Smith 40
Taylor 46
Winland 44
hello

我的表名是条目,我只有两列 varchar 类型的名称和 int 类型的数量

4

1 回答 1

5

我认为您正在执行相同的查询,复制粘贴错误。

于 2013-05-28T19:30:22.150 回答