如果我在Java中嘗試以下查詢,則Java僅返回表格的第一個條目而沒有任何錯誤。但是,如果我將相同的查詢複製到Access,Access將返回全部33個條目。Java查詢僅查找第一個條目
查詢:
SELECT Country, Sum(SumOfNumber) AS number FROM CountryList WHERE Year=2012 AND (Month=1 Or Month=2 Or Month=3) AND Entity='xxx' GROUP BY Country ORDER BY Sum(SumOfNumber) DESC
rs.last();
System.out.println(rs.getRow());
返回1
有什麼建議?
好球員,現在我刪除千卡「ORDER BY總和(SumOfNumber)DESC」和Java返回的所有國家,並在年底扔異常「無效的光標狀態」
public void doconnect(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
conn = DriverManager.getConnection(ConnectURL,user,pw);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String query = "SELECT Country, Sum(SumOfNumbers) AS number FROM CountryList WHERE Year=2012 AND (Month=1 Or Month=2 Or Month=3) AND Entity='xxx' GROUP BY Country ORDER BY Sum(SumOfNumbers) DESC";
System.out.println(query);
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
System.out.println(rs.getString("Country"));
}
rs.close();
}
catch(Exception e){
System.err.println(e);
e.printStackTrace();
}
finally{
if(conn!=null){
try{
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
}
請問您可以包括其餘的代碼嗎? –