i am trying to perform a nested query using csvJDBC.
The tables in question has the following attributes:
comp(comp_id, comp_description)
work_opportunities(wo_id, jp_id)
link_wo_comp (wo_id, comp_id)
The query is:
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;
I have executed the sub query and the main query on their own and they have worked.
This is the code i am using:
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();
}
The error log is this:
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)
Does csvJDBC support nested queries, and if so what is wrong with my code?
Thanks