类java.sql.SQLNonTransientConnectionException源码实例Demo

下面列出了怎么用java.sql.SQLNonTransientConnectionException的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * 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()));
    }
}
 
源代码2 项目: Automekanik   文件: ShtoPunetor.java
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();}
}
 
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);
}
 
源代码4 项目: mariadb-connector-j   文件: BasicFailover.java
@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());
  }
}
 
/**
 * 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()));
    }
}
 
源代码6 项目: gemfirexd-oss   文件: TransactionTest.java
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());
}
 
/**
 * 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();
    }
}
 
/**
 * 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();
    }
}
 
/**
 * 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()));
    }
}
 
/**
 * 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()));
    }
}
 
源代码11 项目: gemfirexd-oss   文件: TransactionTest.java
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());
}
 
/**
 * 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();
    }
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
@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;
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码21 项目: gemfirexd-oss   文件: SectDBSynchronizer.java
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;
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
源代码25 项目: gemfirexd-oss   文件: DBSynchronizer.java
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;
}
 
源代码26 项目: nifi   文件: QueryDatabaseTableRecordTest.java
@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
    }
}
 
源代码27 项目: gemfirexd-oss   文件: DBSynchronizer.java
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;
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
/**
 * 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);
}