我想使用csvJDBC執行嵌套查詢。使用CSVJDBC嵌套查詢
有問題的表具有以下屬性:
comp(comp_id, comp_description)
work_opportunities(wo_id, jp_id)
link_wo_comp (wo_id, comp_id)
查詢是:
SELECT comp_id, count(comp_id)
FROM link_wo_comp
WHERE wo_id IN (SELECT distinct wo_id FROM work_opportunities WHERE jp_id = '1')
GROUP BY comp_id;
我已經進行子查詢,對自己的主查詢和他們工作。
這是代碼我使用:
try {
Class.forName("org.relique.jdbc.csv.CsvDriver");
Connection conn = DriverManager.getConnection("jdbc:relique:csv:"
+ "D:/Desktop/Data/Cleansed/");
Statement stmt = conn.createStatement();
String sql = "SELECT comp_id, count(comp_id) "
+ "FROM link_wo_comp "
+ "WHERE wo_id IN (SELECT distinct wo_id FROM work_opportunities WHERE jp_id = '1') "
+ "GROUP BY comp_id;";
ResultSet results = stmt.executeQuery(sql);
boolean append = true;
CsvDriver.writeToCsv(results, System.out, append);
// Clean up
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
錯誤日誌是這樣的:
java.sql.SQLException: Syntax error: Encountered "" at line 1, column 66.
Was expecting one of:
at org.relique.jdbc.csv.CsvStatement.executeQuery(Unknown Source)
at testing.TestRun.main(TestRun.java:30)
不csvJDBC支持嵌套查詢,如果有什麼錯我的代碼?
謝謝
謝謝了! :) – user2415416