Thread: executeQuery returns postgresql.stat.result
Hi, When I try try { sql="select * from \"qryMonthsYears\""; java.sql.ResultSet resultset=getQuery(sql,connection.createStatement()); } catch(java.sql.SQLException fout) { java.sql.SQLException foutje=fout.getNextException(); out.println("<br>SQL fout: "+fout.getMessage()); while(foutje!=null) { out.print("<br>Ingebedde fout: "+foutje.getMessage()); foutje=fout.getNextException(); } } I get the following exception when I try this: Batch entry 0 select * from "qryMonthsYears"; was aborted. Call getNextException() to see the cause. When I call getNextException(), I get the following result: postgresql.stat.result and stays in the loop. Here is the code for the method getQuery: ResultSet resultset; if(strstatement.startsWith("SELECT")) { resultset=statement.executeQuery(strstatement); if(resultset==null) throw new SQLException("Resultset is null at getQuery()."); if(resultset.getWarnings()==null) return resultset; else { String errmessage=""; while(resultset.getWarnings().getErrorCode()!=0) { errmessage+=resultset.getWarnings().getMessage()+"\n"; resultset.getWarnings().getNextException(); } throw new SQLException("SQL Fout getQuery(): "+errmessage); } } else { connection.setAutoCommit(false); String [] sql=strstatement.split(";"); for(int teller=0;teller<sql.length;teller++) statement.addBatch(sql[teller]+";"); statement.executeBatch(); connection.commit(); connection.setAutoCommit(true); return null; } Please help! Nico.
On Sun, 1 May 2005, Nico wrote: > sql="select * from \"qryMonthsYears\""; >... > if(strstatement.startsWith("SELECT")) >... > else > { > connection.setAutoCommit(false); > String [] sql=strstatement.split(";"); > for(int teller=0;teller<sql.length;teller++) > statement.addBatch(sql[teller]+";"); > statement.executeBatch(); Your own parsing logic is busted and is trying to execute a select in a batch statement, which is not legal. Kris Jurka
The batch statement is ONLY used in case of an update, insert or delete command. When a select command is used, there is no batch used, as you can see in my code. Nico. "Kris Jurka" <books@ejurka.com> schreef in bericht news:Pine.BSO.4.56.0505011230450.1107@leary.csoft.net... > > > On Sun, 1 May 2005, Nico wrote: > >> sql="select * from \"qryMonthsYears\""; >>... >> if(strstatement.startsWith("SELECT")) >>... >> else >> { >> connection.setAutoCommit(false); >> String [] sql=strstatement.split(";"); >> for(int teller=0;teller<sql.length;teller++) >> statement.addBatch(sql[teller]+";"); >> statement.executeBatch(); > > Your own parsing logic is busted and is trying to execute a select in a > batch statement, which is not legal. > > Kris Jurka > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >
On Sun, 1 May 2005, Nico wrote: > The batch statement is ONLY used in case of an update, insert or delete > command. When a select command is used, there is no batch used, as you > can see in my code. No, I can't see that. You have a case mismatch between your sql and your test. A simple examination of the stacktrace from this error would clearly show the wrong code being called. Kris Jurka
I noticed it. Because the exception was captured, it didn't show a stacktrace. I solved it and it works fine now. Thanks. Nico. "Kris Jurka" <books@ejurka.com> schreef in bericht news:Pine.BSO.4.56.0505011302210.22827@leary.csoft.net... > > > On Sun, 1 May 2005, Nico wrote: > >> The batch statement is ONLY used in case of an update, insert or delete >> command. When a select command is used, there is no batch used, as you >> can see in my code. > > No, I can't see that. You have a case mismatch between your sql and your > test. A simple examination of the stacktrace from this error would > clearly show the wrong code being called. > > Kris Jurka > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >