use of java.sql.SQLWarning in project adempiere by adempiere.
the class Convert method execute.
// setVerbose
/**************************************************************************
* Execute SQL Statement (stops at first error).
* If an error occurred hadError() returns true.
* You can get details via getConversionError() or getException()
* @param sqlStatements
* @param conn connection
* @return true if success
* @throws IllegalStateException if no connection
*/
public boolean execute(String sqlStatements, Connection conn) {
if (conn == null)
throw new IllegalStateException("Require connection");
//
String[] sql = convert(sqlStatements);
m_exception = null;
if (m_conversionError != null || sql == null)
return false;
boolean ok = true;
int i = 0;
String statement = null;
try {
if (m_stmt == null)
m_stmt = conn.createStatement();
//
for (i = 0; ok && i < sql.length; i++) {
statement = sql[i];
if (statement.length() == 0) {
if (m_verbose)
log.finer("Skipping empty (" + i + ")");
} else {
if (m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
else
log.info("Executing " + i);
try {
m_stmt.clearWarnings();
int no = m_stmt.executeUpdate(statement);
SQLWarning warn = m_stmt.getWarnings();
if (warn != null) {
if (m_verbose)
log.info("- " + warn);
else {
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("- " + warn);
}
}
if (m_verbose)
log.fine("- ok " + no);
} catch (SQLException ex) {
// Ignore Drop Errors
if (!statement.startsWith("DROP ")) {
ok = false;
m_exception = ex;
}
if (!m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("Error executing " + i + "/" + sql.length + " = " + ex);
}
}
}
// for all statements
} catch (SQLException e) {
m_exception = e;
if (!m_verbose)
log.info("Executing (" + i + ") <<" + statement + ">>");
log.info("Error executing " + i + "/" + sql.length + " = " + e);
return false;
}
return ok;
}
Aggregations