use of java.sql.SQLClientInfoException in project tomcat by apache.
the class DelegatingConnection method setClientInfo.
@Override
public void setClientInfo(final Properties properties) throws SQLClientInfoException {
try {
checkOpen();
_conn.setClientInfo(properties);
} catch (final SQLClientInfoException e) {
throw e;
} catch (final SQLException e) {
throw new SQLClientInfoException("Connection is closed.", EMPTY_FAILED_PROPERTIES, e);
}
}
use of java.sql.SQLClientInfoException in project druid by alibaba.
the class ConnectionTest method test_connection.
@SuppressWarnings("deprecation")
public void test_connection() throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(create_url);
conn.setCatalog(conn.getCatalog());
conn.setClientInfo(conn.getClientInfo());
conn.setHoldability(conn.getHoldability());
conn.setReadOnly(conn.isReadOnly());
conn.setTransactionIsolation(conn.getTransactionIsolation());
conn.setTypeMap(conn.getTypeMap());
try {
conn.setClientInfo("name", "value");
} catch (SQLClientInfoException ex) {
}
try {
conn.createArrayOf("VARCHAR", new String[] { "A", "B" });
} catch (SQLFeatureNotSupportedException ex) {
}
try {
conn.createNClob();
} catch (SQLFeatureNotSupportedException ex) {
}
try {
conn.createSQLXML();
} catch (SQLFeatureNotSupportedException ex) {
}
try {
conn.createStruct("VARCHAR", new String[] { "A", "B" });
} catch (SQLFeatureNotSupportedException ex) {
}
conn.setAutoCommit(false);
Savepoint savePoint = conn.setSavepoint("XX");
conn.releaseSavepoint(savePoint);
pstmt = conn.prepareStatement("INSERT INTO T_BLOB (ID, DATA) VALUES (?, ?)");
Blob blob = conn.createBlob();
blob.setBytes(1, new byte[100]);
pstmt.setInt(1, 1);
pstmt.setBlob(2, blob);
int updateCount = pstmt.executeUpdate();
Assert.assertEquals(1, updateCount);
stmt = conn.createStatement();
conn.nativeSQL("SELECT ID, DATA FROM T_BLOB");
// //////
rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
// just call
rs.getStatement();
while (rs.next()) {
Blob readBlob = rs.getBlob(2);
readBlob.length();
readBlob.getBinaryStream(1, 100).close();
readBlob.getBinaryStream().close();
readBlob.free();
try {
rs.getUnicodeStream(1).close();
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getUnicodeStream("DATA").close();
} catch (SQLFeatureNotSupportedException ex) {
}
}
JdbcUtils.close(rs);
rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
while (rs.next()) {
rs.getBinaryStream(2).close();
}
JdbcUtils.close(rs);
rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
while (rs.next()) {
rs.getBinaryStream("DATA").close();
}
JdbcUtils.close(rs);
rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
while (rs.next()) {
rs.getBytes(2);
}
JdbcUtils.close(rs);
rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
while (rs.next()) {
rs.getBytes("DATA");
}
JdbcUtils.close(rs);
conn.setAutoCommit(true);
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
JdbcUtils.close(pstmt);
JdbcUtils.close(conn);
}
}
use of java.sql.SQLClientInfoException in project jdk8u_jdk by JetBrains.
the class SQLClientInfoExceptionTests method test8.
/**
* Create SQLClientInfoException with message, SQLState, and error code
*/
@Test
public void test8() {
SQLClientInfoException ex = new SQLClientInfoException(reason, state, errorCode, map, t);
assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == errorCode && ex.getFailedProperties().equals(map));
}
use of java.sql.SQLClientInfoException in project jdk8u_jdk by JetBrains.
the class SQLClientInfoExceptionTests method test12.
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
SQLClientInfoException ex = new SQLClientInfoException("Exception 1", map, t1);
SQLClientInfoException ex1 = new SQLClientInfoException("Exception 2", map);
SQLClientInfoException ex2 = new SQLClientInfoException("Exception 3", map, 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();
}
}
use of java.sql.SQLClientInfoException in project jdk8u_jdk by JetBrains.
the class SQLClientInfoExceptionTests method test10.
/**
* Serialize a SQLClientInfoException and make sure you can read it back
* properly
*/
@Test
public void test10() throws Exception {
SQLClientInfoException e = new SQLClientInfoException(reason, state, errorCode, map, t);
SQLClientInfoException ex1 = createSerializedException(e);
assertTrue(reason.equals(ex1.getMessage()) && ex1.getSQLState().equals(state) && cause.equals(ex1.getCause().toString()) && ex1.getErrorCode() == errorCode && ex1.getFailedProperties().equals(map));
}
Aggregations