gpt4 book ai didi

java sqlite - 显示选择

转载 作者:行者123 更新时间:2023-12-01 11:27:43 25 4
gpt4 key购买 nike

这些是我的 table :
http://sqlfiddle.com/#!5/acdb1

我想用 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' 

它应该是什么样子?

最佳答案

您的 SELECT 语句中有很多 id

您必须更改列名称,如下所示:

SELECT stormtrooper.id AS stormtrooper_id, squad.id AS squad_id, platoon.id AS platoon_id, company.id AS company_id, battalion.id AS battalion_id FROM ...

关于java sqlite - 显示选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30686494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com