Reputation: 393
I am running a query using SQL embedded in Java. I have three tables in my database, QUERY, G1, and G2. All of them have the same schema of (SETID, GENEID).
The query I am running is as follows:
SELECT q.SETID, COUNT(q.SETID), g1.SETID, COUNT(g1.SETID)
FROM QUERY AS q
INNER JOIN G1 AS g1 ON q.GENEID = g1.GENEID
GROUP BY q.SETID, g1.SETID
Partial code for execution:
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
String sql = "SELECT q.SETID, COUNT(q.SETID) AS QSIZE, g1.SETID, COUNT(g1.SETID) AS GSIZE FROM QUERY AS q INNER JOIN G1 AS g1 ON q.GENEID = g1.GENEID GROUP BY q.SETID, g1.SETID";
rs = stmt.executeQuery(sql);
rsmd = rs.getMetaData();
When I run this, it throws the following error: ORA-00933: SQL command not properly ended. Could anyone please help me with this error?
Thanks!
Upvotes: 1
Views: 688
Reputation: 7979
Try to:
QUERY
- it looks like reserved wordCOUNT(q.SETID) as Q_CNT
SELECT q.SETID, COUNT(q.SETID) as Q_CNT, g1.SETID, COUNT(g1.SETID) as G1_CNT
FROM `QUERY` AS q
INNER JOIN G1 AS g1 ON q.GENEID = g1.GENEID
GROUP BY q.SETID, g1.SETID;
SELECT QUERY.SETID, COUNT(QUERY.SETID) as Q_CNT, G1.SETID, COUNT(G1.SETID) as G1_CNT
FROM QUERY
INNER JOIN G1 ON QUERY.GENEID = G1.GENEID
GROUP BY QUERY.SETID, G1.SETID;
Upvotes: 1