0
這些都是我的表:
http://sqlfiddle.com/#!5/acdb1的Java源碼 - 顯示選擇
我想在Java中類似raport顯示:
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:project.db");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT stormtrooper.id, squad.id, platoon.id, company.id, battalion.id FROM stormtrooper\n" +
"INNER JOIN squad ON squad.id=stormtrooper.squad\n" +
"INNER JOIN platoon ON platoon.id=squad.platoon\n" +
"INNER JOIN company ON company.id=platoon.company\n" +
"INNER JOIN battalion ON battalion.id=company.battalion;");
String log = "";
while (rs.next()) {
log+=rs.getInt("id") + " | ";
log+=rs.getInt("id") + " | ";
log+=rs.getInt("id") + " | ";
log+=rs.getInt("id") + " | ";
log+=rs.getInt("id") + "\n";
}
jTextArea1.setText(log);
rs.close();
stmt.close();
c.close();
} catch (Exception e) {
jTextArea1.setText(e.getClass().getName() + ": " + e.getMessage());
}
SELECT語句是正確的 - 我查這個。但是,當我試圖在Java中執行此,我得到一個錯誤:
ambiguous column: 'id'
應該如何樣子?
快速,方便,謝謝! – DzikiChrzan