DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=36265>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=36265 Summary: sql task: Create table fails on DB2 Product: Ant Version: 1.6.5 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: Core tasks AssignedTo: [email protected] ReportedBy: [EMAIL PROTECTED] This happens with DB2 version 8.1, and the 8.1 db2jdbc drivers (from IBM I believe). When executing a file with simple sql create table commands, I got: CreateTables: [echo] Creating tables for user **** in jdbc:db2://database:50000/user:deferPrepares=false; driver=com.ibm.db2.jcc.DB2Driver [sql] Executing file: creates.sql [sql] Failed to execute: CREATE TABLE ACCRUAL_RULE ( ACCRUAL_RULE VARCHAR( 80) ) BUILD FAILED build.xml:2963: com.ibm.db2.jcc.b.SQLException: A result has opened by the previous getResultSet() or getUpdateCount() call, Need to call getMoreResults() Here is the stack trace of the exception: at com.ibm.db2.jcc.b.ce.getResultSet(ce.java:491) at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:501) at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:470) at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:664) It appears that the implementation of the sql task does not follow closely the jdbc spec; according to http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#execute(java.lang.String), execute() returns whether a ResultSet is available (and getMoreResults() is similar). Therefore one should not call getResultSet() when execute() or hasMoreResult() has returned false. Similarly, calling getUpdateCount() when execute() or getMoreResults() returned true does not make sense. With the modification below, which I believe follows these rules, the problem went away. In SQLExec, I replaced: ====== BEGIN EXISTING CODE ret = statement.execute(sql); updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); do { if (!ret) { if (updateCount != -1) { updateCountTotal += updateCount; } } else { if (print) { printResults(resultSet, out); } } ret = statement.getMoreResults(); if (ret) { updateCount = statement.getUpdateCount(); resultSet = statement.getResultSet(); } } while (ret); ==================== BEGIN REPLACEMENT CODE boolean ret; int updateCount = 0, updateCountTotal = 0; ret = statement.execute(sql); do { if (!ret) { updateCount = statement.getUpdateCount(); if (updateCount != -1) { updateCountTotal += updateCount; } } else { resultSet = statement.getResultSet(); if (print) { printResults(resultSet, out); } } ret = statement.getMoreResults(); } while (ret); ==================== END REPLACEMENT CODE -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
