本文整理了Java中java.sql.SQLException.getCause()
方法的一些代码示例,展示了SQLException.getCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.getCause()
方法的具体详情如下:
包路径:java.sql.SQLException
类名称:SQLException
方法名:getCause
暂无
代码示例来源:origin: prestodb/presto
private static boolean isPrestoQueryInvalid(SQLException e)
{
for (Throwable t = e.getCause(); t != null; t = t.getCause()) {
if (t.toString().contains(".SemanticException:")) {
return true;
}
if (t.toString().contains(".ParsingException:")) {
return true;
}
if (nullToEmpty(t.getMessage()).matches("Function .* not registered")) {
return true;
}
}
return false;
}
代码示例来源:origin: twosigma/beakerx
public DBConnectionException(String uri, SQLException e) {
super("Connection URI:" + uri + "; " + e.getMessage(), e.getSQLState(), e.getErrorCode(), e.getCause());
}
}
代码示例来源:origin: alibaba/druid
Throwable cause = e.getCause();
for (int i = 0; i < 5 && cause != null; ++i) {
if (cause instanceof SocketTimeoutException) {
代码示例来源:origin: org.postgresql/postgresql
public void handleCompletion() throws SQLException {
updateGeneratedKeys();
SQLException batchException = getException();
if (batchException != null) {
if (isAutoCommit()) {
// Re-create batch exception since rows after exception might indeed succeed.
BatchUpdateException newException = new BatchUpdateException(
batchException.getMessage(),
batchException.getSQLState(),
uncompressUpdateCount()
);
newException.initCause(batchException.getCause());
SQLException next = batchException.getNextException();
if (next != null) {
newException.setNextException(next);
}
batchException = newException;
}
throw batchException;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testConvertFromError() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeUpdate("select CONVERT_FROM('1','INTEGER') from (values(1))");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertTrue("No expected current \"UNSUPPORTED_OPERATION ERROR\" and/or \"Did you mean\"",
e.getMessage().matches("^UNSUPPORTED_OPERATION ERROR(.|\\n)*Did you mean(.|\\n)*"));
throw e;
}
}
}
代码示例来源:origin: spring-projects/spring-framework
while (current.getErrorCode() == 0 && current.getCause() instanceof SQLException) {
current = (SQLException) current.getCause();
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testMaterializingError() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeUpdate("select (res1 = 2016/09/22) res2 from (select (case when (false) then null else "
+ "cast('2016/09/22' as date) end) res1 from (values(1)) foo) foobar");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"PLAN ERROR\"",
e.getMessage(), startsWith("PLAN ERROR"));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteThrowsRight1() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.execute("SELECT one case of syntax error");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteUpdateThrowsRight2() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeUpdate("naughty, naughty query 3");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteQueryThrowsRight2() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeQuery("BAD QUERY 1");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteQueryThrowsRight1() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeQuery("SELECT one case of syntax error");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteUpdateThrowsRight1() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.executeUpdate("SELECT one case of syntax error");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test(expected = SQLException.class)
public void testExecuteThrowsRight2() throws Exception {
final Statement statement = connection.createStatement();
try {
statement.execute("worse query 2");
} catch (SQLException e) {
assertThat("Null getCause(); missing expected wrapped exception",
e.getCause(), notNullValue());
assertThat("Unexpectedly wrapped another SQLException",
e.getCause(), not(instanceOf(SQLException.class)));
assertThat("getCause() not UserRemoteException as expected",
e.getCause(), instanceOf(UserRemoteException.class));
assertThat("No expected current \"SYSTEM ERROR\"/eventual \"PARSE ERROR\"",
e.getMessage(), anyOf(startsWith("SYSTEM ERROR"), startsWith("PARSE ERROR")));
throw e;
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionConnectTriesGreaterThanDrillbitCount() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=5",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof RpcException);
assertTrue(ex.getCause().getCause() instanceof ExecutionException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionConnectTriesLessThanDrillbitCount() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=1",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof RpcException);
assertTrue(ex.getCause().getCause() instanceof ExecutionException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionNegativeConnectTries() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=-5",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof RpcException);
assertTrue(ex.getCause().getCause() instanceof ExecutionException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionConnectTriesEqualsDrillbitCount() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;" + "tries=2",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof RpcException);
assertTrue(ex.getCause().getCause() instanceof ExecutionException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionZeroConnectTries() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=0",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof RpcException);
assertTrue(ex.getCause().getCause() instanceof ExecutionException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testDirectConnectionInvalidConnectTries() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=abc",
getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof InvalidConnectionInfoException);
}
}
代码示例来源:origin: apache/drill
@Test
public void testZKConnectionInvalidConnectTries() throws SQLException {
Connection connection = null;
try {
connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=abc", getDefaultProperties());
fail();
} catch (SQLException ex) {
assertNull(connection);
assertTrue(ex.getCause() instanceof InvalidConnectionInfoException);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!