Browse Source

The instance variable conn was shadowed by a local variable in

execute, failed to remove ; from statement with trailing white space,
made class easier to extend for specialized tasks like <plsql>.
Submitted by:	John H. Lee <jlee@c.kiracom.com>,
                Curt Hagenlocher <curt@hagenlocher.org>,
                Jose  Alberto Fernandez <JFernandez@viquity.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267840 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
ce27573d6e
1 changed files with 9 additions and 8 deletions
  1. +9
    -8
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 9
- 8
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -170,7 +170,6 @@ public class SQLExec extends Task {
* Load the sql file and then execute it
*/
public void execute() throws BuildException {
Connection conn = null;

sqlCommand = sqlCommand.trim();

@@ -200,10 +199,11 @@ public class SQLExec extends Task {
}

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) {
@@ -248,7 +248,7 @@ public class SQLExec extends Task {
log("SQL statements executed successfully", Project.MSG_VERBOSE);
}

private void runStatements(Reader reader) throws SQLException, IOException {
protected void runStatements(Reader reader) throws SQLException, IOException {
String sql = "";
String line = "";
@@ -260,7 +260,8 @@ public class SQLExec extends Task {
if (line.trim().startsWith("--")) continue;
sql += " " + line;
if (sql.trim().endsWith(";")){
sql = sql.trim();
if (sql.endsWith(";")){
log("SQL: " + sql, Project.MSG_VERBOSE);
execSQL(sql.substring(0, sql.length()-1));
sql = "";
@@ -268,7 +269,7 @@ public class SQLExec extends Task {
}
// Catch any statements not followed by ;
if(!sql.trim().equals("")){
if(!sql.equals("")){
execSQL(sql);
}
}catch(SQLException e){
@@ -281,7 +282,7 @@ public class SQLExec extends Task {
/**
* Exec the sql statement.
*/
private void execSQL(String sql) throws SQLException{
protected void execSQL(String sql) throws SQLException{
if (!statement.execute(sql)) {
log(statement.getUpdateCount()+" rows affected",
Project.MSG_VERBOSE);
@@ -289,7 +290,7 @@ public class SQLExec extends Task {

SQLWarning warning = conn.getWarnings();
while(warning!=null){
log(warning + " sql warnging", Project.MSG_VERBOSE);
log(warning + " sql warning", Project.MSG_VERBOSE);
warning=warning.getNextWarning();
}
conn.clearWarnings();


Loading…
Cancel
Save