Java Code Examples for org.postgresql.util.PSQLState

The following examples show how to use org.postgresql.util.PSQLState. These examples are extracted from open source projects. 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
public void testExtractPSQLException() {
  PSQLException psqlException = new PSQLException("fake error", PSQLState.UNEXPECTED_ERROR);
  // passing in the exception itself works
  assertEquals(psqlException, Manager.extractPSQLException(psqlException));

  // wrapping the exception in a SQLException (as done by ORMLite) works
  SQLException wrap1 = new SQLException("wrapper", psqlException);
  assertEquals(psqlException, Manager.extractPSQLException(wrap1));

  // ORMLite can also double wrap the exception
  SQLException wrap2 = new SQLException("double", wrap1);
  assertEquals(psqlException, Manager.extractPSQLException(wrap2));

  // SQLException with some other kind of exception: null
  SQLException other = new SQLException("other", new RuntimeException("cause"));
  Throwable t = new Throwable("hello", psqlException);
  assertEquals(psqlException, Manager.extractPSQLException(t));
Example 2
Source Project: crate   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testEmptyStatement() throws Exception {
    try (Connection conn = DriverManager.getConnection(url(RW), properties)) {
        assertThat(conn.createStatement().execute(""), is(false));

        try {
            fail("executeQuery with empty query should throw a 'No results were returned by the query' error");
        } catch (PSQLException e) {
            // can't use expectedException.expectMessage because error messages are localized and locale is randomized
            assertThat(e.getSQLState(), is(PSQLState.NO_DATA.getState()));