在我們的查詢中,我們有2個我們想要加入的表格。但是,我們得到以下錯誤:無法加入2個表格
org.postgresql.util.PSQLException: ERROR: missing FROM-clause entry
for table "component" Position: 48 at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:406)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:286) at datab.Datab.testDB(Datab.java:73) at datab.Datab.main(Datab.java:60)
這裏是我的代碼:
public static void testDB(Connection con){
//RUN AN EXAMPLE QUERY
try {
if (!con.isClosed())
{
Statement st = con.createStatement();
String query = "SELECT * FROM \"Component\" inner join \"Kind\" on Component.Kind_ID = Kind.ID";
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
另一個很好的例子,爲什麼加引號的標識符是不是一個好主意。 –