Java SQL Table getBatchResultMessage(String tableName, int rowIdx, int resultCode)

Here you can find the source of getBatchResultMessage(String tableName, int rowIdx, int resultCode)

Description

Returns the logging message corresponding to the given result code of a batch message.

License

Apache License

Parameter

Parameter Description
tableName The name of the table that the batch update/insert was performed on
rowIdx The index of the row within the batch for which this code is
resultCode The code

Return

The string message or null if the code does not indicate an error

Declaration

public static String getBatchResultMessage(String tableName, int rowIdx, int resultCode) 

Method Source Code


//package com.java2s;
/*//from   w ww. j  av  a 2s.  c  o  m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.sql.Statement;

public class Main {
    /**
     * Returns the logging message corresponding to the given result code of a batch message.
     * Note that these code values are only available in JDBC 3 and newer (see
     * {@link java.sql.Statement} for details).
     * 
     * @param tableName  The name of the table that the batch update/insert was performed on
     * @param rowIdx     The index of the row within the batch for which this code is
     * @param resultCode The code
     * @return The string message or <code>null</code> if the code does not indicate an error
     */
    public static String getBatchResultMessage(String tableName, int rowIdx, int resultCode) {
        if (resultCode < 0) {
            try {
                if (resultCode == Statement.class.getField("SUCCESS_NO_INFO").getInt(null)) {
                    return null;
                } else if (resultCode == Statement.class.getField("EXECUTE_FAILED").getInt(null)) {
                    return "The batch insertion of row " + rowIdx + " into table " + tableName
                            + " failed but the driver is able to continue processing";
                } else {
                    return "The batch insertion of row " + rowIdx + " into table " + tableName
                            + " returned an undefined status value " + resultCode;
                }
            } catch (Exception ex) {
                throw new UnsupportedOperationException("The batch result codes are not supported");
            }
        } else {
            return null;
        }
    }
}

Related

  1. dumpTable(Connection connection, String tablename)
  2. dumpTableToFile(Connection con, String table, String fileName)
  3. exportTableData(String tableName, Connection con)
  4. getAllTableNames(Connection connection)
  5. getAllTables(Connection conn)
  6. getCount(Connection conn, String tableName)
  7. getIdNumber(String tableName)
  8. getImmutableDefaults()
  9. getLastCreatedEntry(Connection conn, String tableName)