Java Code Examples for java.sql.SQLNonTransientConnectionException

The following examples show how to use java.sql.SQLNonTransientConnectionException. 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
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 2
Source Project: Automekanik   Source File: ShtoPunetor.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void rregullo(int id){
    try {
        if (!user.getText().isEmpty() && !pw.getText().isEmpty()) {
            String sql = "update Admin set emri = '" + user.getText() + "', fjalekalimi = '" + pw.getText() +
                    "' where id = " + id;
            System.out.println("ID: " + id);
            Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
            Statement stmt = conn.createStatement();
            stmt.execute(sql);
            conn.close();
            new Mesazhi("Sukses", "", "Te dhenat u ruajten me sukses. Ju lutem restartoni programin.");
            stage.close();
        }
        else new Mesazhi("Gabim", "", "Fushat duhet te plotesohen para se te vazhdoni");
    }catch (SQLNonTransientConnectionException fu){}
    catch (NullPointerException npe){new Mesazhi("Info", "Gabim", "Fusha qmimi duhet te permbaj vetem numra.");}
    catch (Exception ex){ex.printStackTrace();}
}
 
Example 3
public CassandraConnection getConnection(String user, String password) throws SQLException
{
    Properties props = new Properties();
    
    this.user = user;
    this.password = password;
    
    if (this.serverName!=null) props.setProperty(TAG_SERVER_NAME, this.serverName);
    else throw new SQLNonTransientConnectionException(HOST_REQUIRED);
    props.setProperty(TAG_PORT_NUMBER, ""+this.portNumber);
    if (this.databaseName!=null) props.setProperty(TAG_DATABASE_NAME, this.databaseName);
    if (user!=null) props.setProperty(TAG_USER, user);
    if (password!=null) props.setProperty(TAG_PASSWORD, password);
    if (this.version != null) props.setProperty(TAG_CQL_VERSION, version);
    if (this.consistency != null) props.setProperty(TAG_CONSISTENCY_LEVEL, consistency);

    String url = PROTOCOL+createSubName(props);
    return (CassandraConnection) DriverManager.getConnection(url, props);
}
 
Example 4
@Test
public void failoverRetry() throws Throwable {
  try (Connection connection =
      DriverManager.getConnection(
          "jdbc:mariadb:failover//"
              + ((hostname != null) ? hostname : "localhost")
              + ":"
              + port
              + "/"
              + database
              + "?user="
              + username
              + ((password != null) ? "&password=" + password : "")
              + ((options.useSsl != null) ? "&useSsl=" + options.useSsl : "")
              + ((options.serverSslCert != null) ? "&serverSslCert=" + options.serverSslCert : "")
              + "&socketTimeout=1000")) {
    try (Statement stmt = connection.createStatement()) {
      stmt.execute("SELECT SLEEP(10)");
      fail();
    } catch (SQLNonTransientConnectionException e) {
      // normal error : fail to reconnect, since second execution fail too
    }
    assertTrue(connection.isClosed());
  }
}
 
Example 5
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 6
Source Project: gemfirexd-oss   Source File: TransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
public void Debug_tests_43222() throws SQLException {
  final Connection conn = getConnection();
  final Statement stmt = conn.createStatement();
  conn.setTransactionIsolation(getIsolationLevel());
  stmt.execute("create table warehouse (    w_id        integer   not null,"
      + "    w_ytd       decimal(12,2),"
      + "    w_tax       decimal(4,4),"
      + "    w_name      varchar(10)) replicate"+getSuffix());

  stmt.execute("alter table warehouse add constraint pk_warehouse "
      + "primary key (w_id)");

  stmt.execute("insert into warehouse values(1, 0.0, 0.0, 'name1'), "
      + "(2, 0.2, 0.0, 'name2')");
  conn.commit();

  int i = stmt.executeUpdate("UPDATE warehouse SET w_ytd = w_ytd + 4998.73 "
      + "WHERE w_id = 1");
  System.out.println(i);
  SQLNonTransientConnectionException ex = new SQLNonTransientConnectionException();
  System.out.println("ex.getSQLState returned: " + ex.getSQLState());
}
 
Example 7
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("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 8
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("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 9
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 10
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
Example 11
Source Project: gemfirexd-oss   Source File: TransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
public void Debug_tests_43222() throws SQLException {
  final Connection conn = getConnection();
  final Statement stmt = conn.createStatement();
  conn.setTransactionIsolation(getIsolationLevel());
  stmt.execute("create table warehouse (    w_id        integer   not null,"
      + "    w_ytd       decimal(12,2),"
      + "    w_tax       decimal(4,4),"
      + "    w_name      varchar(10)) replicate"+getSuffix());

  stmt.execute("alter table warehouse add constraint pk_warehouse "
      + "primary key (w_id)");

  stmt.execute("insert into warehouse values(1, 0.0, 0.0, 'name1'), "
      + "(2, 0.2, 0.0, 'name2')");
  conn.commit();

  int i = stmt.executeUpdate("UPDATE warehouse SET w_ytd = w_ytd + 4998.73 "
      + "WHERE w_id = 1");
  System.out.println(i);
  SQLNonTransientConnectionException ex = new SQLNonTransientConnectionException();
  System.out.println("ex.getSQLState returned: " + ex.getSQLState());
}
 
Example 12
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException("Exception 1", t1);
    SQLNonTransientConnectionException ex1 =
            new SQLNonTransientConnectionException("Exception 2");
    SQLNonTransientConnectionException ex2 =
            new SQLNonTransientConnectionException("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 13
/**
 * Create SQLNonTransientConnectionException with null Throwable
 */
@Test
public void test8() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException((Throwable)null);
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 14
/**
 * Create SQLNonTransientConnectionException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example 15
/**
 * Create SQLNonTransientConnectionException with message, and Throwable
 */
@Test
public void test7() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 16
/**
 * Serialize a SQLNonTransientConnectionException and make sure you can
 * read it back properly
 */
@Test
public void test10() throws Exception {
    SQLNonTransientConnectionException e =
            new SQLNonTransientConnectionException(reason, state, errorCode, t);
    SQLNonTransientConnectionException ex1 =
            createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage())
            && ex1.getSQLState().equals(state)
            && cause.equals(ex1.getCause().toString())
            && ex1.getErrorCode() == errorCode);
}
 
Example 17
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	if (ex instanceof SQLTransientException) {
		if (ex instanceof SQLTransientConnectionException) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTransactionRollbackException) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLTimeoutException) {
			return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLNonTransientException) {
		if (ex instanceof SQLNonTransientConnectionException) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLDataException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLIntegrityConstraintViolationException) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLInvalidAuthorizationSpecException) {
			return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
		}
		else if (ex instanceof SQLSyntaxErrorException) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (ex instanceof SQLFeatureNotSupportedException) {
			return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
		}
	}
	else if (ex instanceof SQLRecoverableException) {
		return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
	}

	// Fallback to Spring's own SQL state translation...
	return null;
}
 
Example 18
/**
 * Create SQLNonTransientConnectionException with message, SQLState, errorCode, and Throwable
 */
@Test
public void test5() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state, errorCode, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == errorCode);
}
 
Example 19
/**
 * Create SQLNonTransientConnectionException with message, SQLState, and Throwable
 */
@Test
public void test6() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 20
/**
 * Create SQLNonTransientConnectionException with message, and Throwable
 */
@Test
public void test7() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState() == null
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}
 
Example 21
Source Project: gemfirexd-oss   Source File: SectDBSynchronizer.java    License: Apache License 2.0 5 votes vote down vote up
protected SqlExceptionHandler checkExceptionType(SQLException sqle) {
  if (sqle != null) {
    if (sqle instanceof SQLNonTransientConnectionException) {
      // will need to connect again
      return SqlExceptionHandler.REFRESH;
    }
    if (sqle instanceof SQLIntegrityConstraintViolationException) {
      // constraint violations can happen in retries, so default action is to
      // IGNORE them; when errorFile is provided then it will be logged to
      // that in XML format in any case
      return SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLNonTransientException) {
      // if numErrorTries is defined, then retry some number of times else
      // ignore after having logged warning since retry is not likely to help
      return this.numErrorTries > 0 ? SqlExceptionHandler.IGNORE_BREAK_LOOP
          : SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLTransientException) {
      // skip the remaining batch and retry whole batch again
      return SqlExceptionHandler.IGNORE_BREAK_LOOP;
    }
    if (sqle instanceof BatchUpdateException) {
      return checkExceptionType(sqle.getNextException());
    }
  }
  return null;
}
 
Example 22
/**
 * Create SQLNonTransientConnectionException with no-arg constructor
 */
@Test
public void test1() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException();
    assertTrue(ex.getMessage() == null
            && ex.getSQLState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 23
/**
 * Create SQLNonTransientConnectionException and setting all objects to null
 */
@Test
public void test() {
    SQLNonTransientConnectionException e =
            new SQLNonTransientConnectionException(null,
            null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
 
Example 24
/**
 * Create SQLNonTransientConnectionException with message, and SQLState
 */
@Test
public void test3() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
 
Example 25
Source Project: gemfirexd-oss   Source File: DBSynchronizer.java    License: Apache License 2.0 5 votes vote down vote up
protected SqlExceptionHandler checkExceptionType(SQLException sqle) {
  if (sqle != null) {
    if (sqle instanceof SQLNonTransientConnectionException) {
      // will need to connect again
      return SqlExceptionHandler.REFRESH;
    }
    if (sqle instanceof SQLIntegrityConstraintViolationException) {
      // constraint violations can happen in retries, so default action is to
      // IGNORE them; when errorFile is provided then it will be logged to
      // that in XML format in any case
      return SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLNonTransientException) {
      // if numErrorTries is defined, then retry some number of times else
      // ignore after having logged warning since retry is not likely to help
      return this.numErrorTries > 0 ? SqlExceptionHandler.IGNORE_BREAK_LOOP
          : SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLTransientException) {
      // skip the remaining batch and retry whole batch again
      return SqlExceptionHandler.IGNORE_BREAK_LOOP;
    }
    if (sqle instanceof BatchUpdateException) {
      return checkExceptionType(sqle.getNextException());
    }
  }
  return null;
}
 
Example 26
Source Project: nifi   Source File: QueryDatabaseTableRecordTest.java    License: Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void cleanUpAfterClass() throws Exception {
    try {
        DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
    } catch (SQLNonTransientConnectionException e) {
        // Do nothing, this is what happens at Derby shutdown
    }
    // remove previous test database, if any
    final File dbLocation = new File(DB_LOCATION);
    try {
        FileUtils.deleteFile(dbLocation, true);
    } catch (IOException ioe) {
        // Do nothing, may not have existed
    }
}
 
Example 27
Source Project: gemfirexd-oss   Source File: DBSynchronizer.java    License: Apache License 2.0 5 votes vote down vote up
protected SqlExceptionHandler checkExceptionType(SQLException sqle) {
  if (sqle != null) {
    if (sqle instanceof SQLNonTransientConnectionException) {
      // will need to connect again
      return SqlExceptionHandler.REFRESH;
    }
    if (sqle instanceof SQLIntegrityConstraintViolationException) {
      // constraint violations can happen in retries, so default action is to
      // IGNORE them; when errorFile is provided then it will be logged to
      // that in XML format in any case
      return SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLNonTransientException) {
      // if numErrorTries is defined, then retry some number of times else
      // ignore after having logged warning since retry is not likely to help
      return this.numErrorTries > 0 ? SqlExceptionHandler.IGNORE_BREAK_LOOP
          : SqlExceptionHandler.IGNORE;
    }
    if (sqle instanceof SQLTransientException) {
      // skip the remaining batch and retry whole batch again
      return SqlExceptionHandler.IGNORE_BREAK_LOOP;
    }
    if (sqle instanceof BatchUpdateException) {
      return checkExceptionType(sqle.getNextException());
    }
  }
  return null;
}
 
Example 28
/**
 * Create SQLNonTransientConnectionException with message, SQLState, and error code
 */
@Test
public void test4() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == errorCode);
}
 
Example 29
/**
 * Serialize a SQLNonTransientConnectionException and make sure you can
 * read it back properly
 */
@Test
public void test10() throws Exception {
    SQLNonTransientConnectionException e =
            new SQLNonTransientConnectionException(reason, state, errorCode, t);
    SQLNonTransientConnectionException ex1 =
            createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage())
            && ex1.getSQLState().equals(state)
            && cause.equals(ex1.getCause().toString())
            && ex1.getErrorCode() == errorCode);
}
 
Example 30
/**
 * Create SQLNonTransientConnectionException with message, SQLState, and Throwable
 */
@Test
public void test6() {
    SQLNonTransientConnectionException ex =
            new SQLNonTransientConnectionException(reason, state, t);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getSQLState().equals(state)
            && cause.equals(ex.getCause().toString())
            && ex.getErrorCode() == 0);
}