Search in sources :

Example 46 with SQLWarning

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;
}
Also used : SQLWarning(java.sql.SQLWarning) SQLException(java.sql.SQLException)

Aggregations

SQLWarning (java.sql.SQLWarning)46 SQLException (java.sql.SQLException)17 Test (org.testng.annotations.Test)15 BaseTest (util.BaseTest)15 Statement (java.sql.Statement)12 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 Connection (java.sql.Connection)3 ResultSetMetaData (java.sql.ResultSetMetaData)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 CallableStatement (java.sql.CallableStatement)2 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 SQLClientInfoException (java.sql.SQLClientInfoException)1