Search in sources :

Example 16 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test3.

/**
     * Create SQLDataException with message, and SQLState
     */
@Test
public void test3() {
    SQLDataException ex = new SQLDataException(reason, state);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 17 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test9.

/**
     * Create SQLDataException with Throwable
     */
@Test
public void test9() {
    SQLDataException ex = new SQLDataException(t);
    assertTrue(ex.getMessage().equals(cause) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 18 with SQLDataException

use of java.sql.SQLDataException in project metacat by Netflix.

the class JdbcConnectorTableService method buildSourceType.

/**
 * Rebuild a source type definition.
 *
 * @param type      The base type e.g. VARCHAR
 * @param size      The size if applicable to the {@code type}
 * @param precision The precision if applicable to the {@code type} e.g. DECIMAL's
 * @return The representation of source type e.g. INTEGER, VARCHAR(50) or DECIMAL(20, 10)
 * @throws SQLDataException When size or precision can't be parsed to integers if non null
 */
protected String buildSourceType(@Nonnull @NonNull final String type, @Nullable final String size, @Nullable final String precision) throws SQLDataException {
    if (size != null) {
        final int sizeInt;
        try {
            sizeInt = Integer.parseInt(size);
        } catch (final NumberFormatException nfe) {
            throw new SQLDataException("Size field could not be converted to integer", nfe);
        }
        // Make sure if the type is unsigned it's created correctly
        final String baseType;
        final String afterMagnitude;
        final int unsignedIndex = StringUtils.indexOfIgnoreCase(type, UNSIGNED);
        if (unsignedIndex != -1) {
            baseType = StringUtils.trim(type.substring(0, unsignedIndex));
            afterMagnitude = type.substring(unsignedIndex);
        } else {
            baseType = type;
            afterMagnitude = null;
        }
        if (precision != null) {
            final int precisionInt;
            try {
                precisionInt = Integer.parseInt(precision);
            } catch (final NumberFormatException nfe) {
                throw new SQLDataException("Precision field could not be converted to integer", nfe);
            }
            return baseType + LEFT_PAREN + sizeInt + COMMA_SPACE + precisionInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY);
        } else {
            return baseType + LEFT_PAREN + sizeInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY);
        }
    } else {
        return type;
    }
}
Also used : SQLDataException(java.sql.SQLDataException)

Aggregations

SQLDataException (java.sql.SQLDataException)18 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 SQLException (java.sql.SQLException)4 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 Map (java.util.Map)1 BeanPropertyRowMapper (org.springframework.jdbc.core.BeanPropertyRowMapper)1 ColumnMapRowMapper (org.springframework.jdbc.core.ColumnMapRowMapper)1 RowMapper (org.springframework.jdbc.core.RowMapper)1 RowMapperResultSetExtractor (org.springframework.jdbc.core.RowMapperResultSetExtractor)1