我的程序有兩個數據庫表:GameInfo和Characters。 這是如何工作的:一個遊戲有4個不同地名的地圖,每個添加到遊戲中的角色必須分配4個地圖中的任何一個。現在我有了一個sql語句,它返回一個名爲「Expr1001」的結果集,其中包含每個地圖上的字符數。然後,我需要將這些信息添加到jTable中,並將地圖上每個字符的相應數量與mapname關聯起來。從一個與另一個SQL表中獲取數據的計數並在java中使用此數據
我與返回每個地圖上的字符數的查詢結果集:
ResultSet qs = dbm.queryDatabase("SELECT Expr1001 FROM (SELECT GameInfo.mapname, SUM(IIF(Map = GameInfo.mapname,1,0)) FROM (SELECT * FROM [Character] INNER JOIN Player ON Character.PlayerID=Player.[ID]) AS A RIGHT JOIN GameInfo ON A.Character.map = GameInfo.mapname GROUP BY GameInfo.mapname) AS [%$##@_Alias]");
整個方法,從數據庫中的的GameInfo表獲取遊戲信息,其中包括遊戲ID名和映射的唯一。
public Game[] getGameInfo(){
Game[] arr = null; //Creates an array of Games
try { //getting list from database
ResultSet rs = dbm.queryDatabase("Select Count(GameID) as NumGames from GameInfo");
//While there are still more rows to read from the database.
rs.next();
int count = rs.getInt("NumGames");
arr = new Game[count];
String sql = "Select * from GameInfo";
// System.out.println(sql);
rs = dbm.queryDatabase(sql);
//Take the info from the current row
//Add the info to the array
ResultSet qs = dbm.queryDatabase("SELECT Expr1001 FROM (SELECT GameInfo.mapname, SUM(IIF(Map = GameInfo.mapname,1,0)) FROM (SELECT * FROM [Character] INNER JOIN Player ON Character.PlayerID=Player.[ID]) AS A RIGHT JOIN GameInfo ON A.Character.map = GameInfo.mapname GROUP BY GameInfo.mapname) AS [%$##@_Alias]");
for(int i = 0; rs.next(); i++){
arr[i] = new Game(
rs.getInt("GameInfo.GameID"),
rs.getString("GameInfo.mapname"),
qs.getInt(i));
}//Creates a Game from the currently selected info
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Failed to get Games");
e.printStackTrace();
}
return arr;
}
}
的數據然後加入到JTable這是在GameInfoPanel類面板上:
public void refreshTable() {
//remove old stuff
refreshing = true;
Game[] arr = gim.getGameInfo();
DefaultTableModel model = (DefaultTableModel) GameInfoTable.getModel();
while (model.getRowCount() > 0) {
model.removeRow(0);
}
for (int i = 0; i < arr.length; i++) {
model.addRow(new Object[]{
arr[i].getNumberOfCharacters(),
arr[i].getID(),
arr[i].getMapName()});
}
refreshing = false;
//load new data from database using manager
}
總是收到指向該結果集適量線錯誤:「用戶缺少特權或對象找不到:A.CHARACTER.MAP「,當我嘗試運行程序時,即使將此語句複製到Microsoft Access並運行它時,也沒有問題。
請幫忙! 謝謝。
(我還是在學校,所以不是真的對這個天才在所有所以請可憐,如果我做了一些愚蠢的事情)
嘗試更換'A.CHARACTER.MAP'用'CHARACTER.MAP' –
@AdamMartin錯誤現在是:用戶缺少特權或找不到對象:CHARACTER.MAP – James