You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "John H. Lee" <jl...@c.kiracom.com> on 2000/07/26 02:47:15 UTC

[PATCH] SQLExec.java NullPointerException

Fixes two silly errors:

    1. execute() created the Connection in a local variable,
       leaving the Connection used in other methods null.
    2. conn.setAutoCommit() was being called before conn
       was set.

-John




Index: SQLExec.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v

retrieving revision 1.3
diff -u -r1.3 SQLExec.java
--- SQLExec.java        2000/07/25 13:55:07     1.3
+++ SQLExec.java        2000/07/26 00:43:44
@@ -170,7 +170,6 @@
      * Load the sql file and then execute it
      */
     public void execute() throws BuildException {
-        Connection conn = null;

         sqlCommand = sqlCommand.trim();

@@ -200,10 +199,11 @@
         }

         try{
-            conn.setAutoCommit(autocommit);
-
             log("connecting to " + url, Project.MSG_VERBOSE );
             conn = DriverManager.getConnection(url, userId, password);
+
+            conn.setAutoCommit(autocommit);
+
             statement = conn.createStatement();

             if (sqlCommand.length() != 0) {