These are my tables:
http://ift.tt/1IsKwNl
I want to display in Java something like 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 statement is correct - I checked this. But when I try execute this in Java, I'm getting an error:
ambiguous column: 'id'
How should it looks like?
Aucun commentaire:
Enregistrer un commentaire