java.sql.SQLDataException Java Examples

The following examples show how to use java.sql.SQLDataException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQLDataExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #2
Source File: SQLDataExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #3
Source File: SQLDataExceptionTests.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #4
Source File: SQLDataExceptionTests.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #5
Source File: SQLDataExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example #6
Source File: SQLDataExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, and Throwable
 */
@Test
public void test6() {
    SQLDataException ex = new SQLDataException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example #9
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with null Throwable
 */
@Test
public void test8() {
    SQLDataException ex = new SQLDataException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #10
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with null Throwable
 */
@Test
public void test8() {
    SQLDataException ex = new SQLDataException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #11
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example #12
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example #13
Source File: SQLDataExceptionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, and Throwable
 */
@Test
public void test6() {
    SQLDataException ex = new SQLDataException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example #14
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public void testGetNCharacterStream(ResultSet resultSet) throws SQLException {
  try {
    g.getNCharacterStream(resultSet);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example #15
Source File: SQLDataExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with no-arg constructor
 */
@Test
public void test1() {
    SQLDataException ex = new SQLDataException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #16
Source File: SQLDataExceptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with no-arg constructor
 */
@Test
public void test1() {
    SQLDataException ex = new SQLDataException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example #17
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public void testGetRef(ResultSet resultSet) throws SQLException {
  try {
    g.getRef(resultSet);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example #18
Source File: SQLDataExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #19
Source File: SQLDataExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLDataException ex = new SQLDataException("Exception 1", t1);
    SQLDataException ex1 = new SQLDataException("Exception 2");
    SQLDataException ex2 = new SQLDataException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example #20
Source File: SQLDataExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException and setting all objects to null
 */
@Test
public void test() {
    SQLDataException e = new SQLDataException(null, null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
 
Example #21
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public void testGetDouble(ResultSet resultSet) throws SQLException {
  try {
    g.getDouble(resultSet);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example #22
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public void testGetByte(ResultSet resultSet) throws SQLException {
  try {
    g.getByte(resultSet);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example #23
Source File: ErrorMessageUtilTest.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBuildSimpleErrorMessage() {
  assertThat(
      buildErrorMessage(new SQLDataException("some message", "some state", 422)),
      is("some message")
  );
}
 
Example #24
Source File: SQLDataExceptionTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example #25
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
public void testGetLong(ResultSet resultSet) throws SQLException {
  try {
    g.getLong(resultSet);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example #26
Source File: SQLDataExceptionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example #27
Source File: SQLDataExceptionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #28
Source File: JdbcCommon.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Sets all of the appropriate parameters on the given PreparedStatement, based on the given FlowFile attributes.
 *
 * @param stmt the statement to set the parameters on
 * @param attributes the attributes from which to derive parameter indices, values, and types
 * @throws SQLException if the PreparedStatement throws a SQLException when the appropriate setter is called
 */
public static void setParameters(final PreparedStatement stmt, final Map<String, String> attributes) throws SQLException {
    for (final Map.Entry<String, String> entry : attributes.entrySet()) {
        final String key = entry.getKey();
        final Matcher matcher = SQL_TYPE_ATTRIBUTE_PATTERN.matcher(key);
        if (matcher.matches()) {
            final int parameterIndex = Integer.parseInt(matcher.group(1));

            final boolean isNumeric = NUMBER_PATTERN.matcher(entry.getValue()).matches();
            if (!isNumeric) {
                throw new SQLDataException("Value of the " + key + " attribute is '" + entry.getValue() + "', which is not a valid JDBC numeral type");
            }

            final int jdbcType = Integer.parseInt(entry.getValue());
            final String valueAttrName = "sql.args." + parameterIndex + ".value";
            final String parameterValue = attributes.get(valueAttrName);
            final String formatAttrName = "sql.args." + parameterIndex + ".format";
            final String parameterFormat = attributes.containsKey(formatAttrName)? attributes.get(formatAttrName):"";

            try {
                JdbcCommon.setParameter(stmt, valueAttrName, parameterIndex, parameterValue, jdbcType, parameterFormat);
            } catch (final NumberFormatException nfe) {
                throw new SQLDataException("The value of the " + valueAttrName + " is '" + parameterValue + "', which cannot be converted into the necessary data type", nfe);
            } catch (ParseException pe) {
                throw new SQLDataException("The value of the " + valueAttrName + " is '" + parameterValue + "', which cannot be converted to a timestamp", pe);
            } catch (UnsupportedEncodingException uee) {
                throw new SQLDataException("The value of the " + valueAttrName + " is '" + parameterValue + "', which cannot be converted to UTF-8", uee);
            }
        }
    }
}
 
Example #29
Source File: SQLDataExceptionTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException and setting all objects to null
 */
@Test
public void test() {
    SQLDataException e = new SQLDataException(null, null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
 
Example #30
Source File: SQLDataExceptionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create SQLDataException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}