0

i'm trying to test the existance of a database using ant.

<sql driver="mydriver" url="myurl" userid="myuserid" passworkd="mypassword"
faiOnConnectionError="false"
onerror="continue"
warningproperty="db.empty"
errorproperty="db.empty"
src="mySrc"
print="false"
output="db.present"
showWarnings="false" />

When the database does not exists, i have a message in the console indicating that the database does not exists (which is normal).

My need is to deactivate the display of this message, is there a way that can do this?

Rebse
  • 10,307
  • 2
  • 38
  • 66
Monster
  • 179
  • 5
  • 20
  • It looks like `` writes the output to a file named `db.present`. You can use the `` task with a `` that uses the `negate` attribute of ``. – Chad Nouis Nov 07 '13 at 16:07
  • I don't get your answer, the file db.present does not have any think to do with my problem. The message that i want to desactivate (not to be displayed) is displayed in the console (not in the file) – Monster Nov 07 '13 at 18:34
  • To control console output, you can create a [Listener](http://ant.apache.org/manual/listeners.html) for message logged events. – Chad Nouis Nov 07 '13 at 20:38

1 Answers1

0

From the source of org.apache.tools.ant.taskdefs.JDBCTask (ant 1.9.2), line 379-387 :

} catch (SQLException e) {
    // failed to connect
    if (!failOnConnectionError) {
        log("Failed to connect: " + e.getMessage(), Project.MSG_WARN);
        return null;
    } else {
        throw new BuildException(e, getLocation());
    }
}

Assuming you're using the default Loglevel Info, all messages with messagelevel error, warn and info get logged. To get rid off that output with messagelevel warn, either patch the JDBCTask and adjust the messagelevel on line 382 to Project.MSG_VERBOSE or Project.MSG_DEBUG or use one of the solutions in the answers to
Make ant quiet without the -q flag?

Community
  • 1
  • 1
Rebse
  • 10,307
  • 2
  • 38
  • 66
  • This solution seems to be OK : But my need, is not to hide ALL kinds of error messages (which is done by the script above), i need to hide only one message concerning the none existance of the database.* Is there any way to do this ? – Monster Nov 08 '13 at 10:04
  • Use .. your sql task goes here .. to hide only the message from sql task. See http://stackoverflow.com/a/5464009/130683 for setloglevel task. – Rebse Nov 08 '13 at 11:06
  • It seems to be impossible to catch only one error generated by ant. There is some solution to catch all of them, by this is not a good one. Thanks for your help :) – Monster Dec 13 '13 at 10:54
  • There is a way via Flaka ant addon (http://code.google.com/p/flaka/). His try-catch task is able to handle a specific exception class ! See Flaka manual section 9.1 and especially 9.1.3 => http://workbench.haefelinger.it/flaka/download/manual/flaka-1.2.2.html – Rebse Dec 13 '13 at 16:02