use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.
the class DruidPooledStatementTest method test_isCloseOnCompletion_error.
public void test_isCloseOnCompletion_error() throws Exception {
Connection conn = dataSource.getConnection();
DruidPooledStatement stmt = (DruidPooledStatement) conn.createStatement();
Assert.assertEquals(0, dataSource.getPoolingCount());
Assert.assertEquals(1, dataSource.getActiveCount());
Assert.assertEquals(0, dataSource.getErrorCount());
Exception error = null;
try {
stmt.isCloseOnCompletion();
} catch (SQLFeatureNotSupportedException e) {
error = e;
}
Assert.assertNotNull(error);
Assert.assertEquals(0, dataSource.getErrorCount());
stmt.close();
conn.close();
Assert.assertEquals(1, dataSource.getPoolingCount());
Assert.assertEquals(0, dataSource.getActiveCount());
}
use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.
the class PrecallTest method test_precall.
public void test_precall() throws Exception {
Connection conn = null;
CallableStatement cstmt = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(create_url);
cstmt = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY);
cstmt.close();
cstmt = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
cstmt.close();
cstmt = conn.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
try {
cstmt.setObject(1, null);
} catch (SQLDataException ex) {
}
try {
cstmt.setObject(1, null, Types.VARCHAR);
} catch (SQLDataException ex) {
}
try {
cstmt.setURL(1, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setURL("F1", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setSQLXML(1, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setSQLXML("F1", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setRowId(1, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setRowId("F1", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNString(1, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNString("F1", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setBlob(1, (Blob) null);
} catch (SQLDataException ex) {
}
try {
cstmt.setBlob("F1", (Blob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setBlob(1, (InputStream) null);
} catch (SQLDataException ex) {
}
try {
cstmt.setBlob("F1", (InputStream) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setBlob(1, (InputStream) null, 0);
} catch (SQLDataException ex) {
}
try {
cstmt.setBlob("F1", (InputStream) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setClob(1, (Clob) null);
} catch (SQLDataException ex) {
}
try {
cstmt.setClob("F1", (Clob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setClob(1, (Reader) null);
} catch (SQLDataException ex) {
}
try {
cstmt.setClob("F1", (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setClob(1, (Reader) null, 0);
} catch (SQLDataException ex) {
}
try {
cstmt.setClob("F1", (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob(1, (NClob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob("F1", (NClob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob(1, (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob("F1", (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob(1, (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNClob("F1", (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNCharacterStream(1, (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNCharacterStream("F1", (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNCharacterStream(1, (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNCharacterStream("F1", (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNull("F1", Types.VARCHAR);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.setNull("F1", Types.VARCHAR, "VARCHAR");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getRef(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getRef("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getClob(1);
} catch (SQLException ex) {
}
try {
cstmt.getClob("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getArray(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getArray("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getURL(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getURL("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getSQLXML(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getSQLXML("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getRowId(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getRowId("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNClob(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNClob("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNString(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNString("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNCharacterStream(1);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
cstmt.getNCharacterStream("F1");
} catch (SQLFeatureNotSupportedException ex) {
}
cstmt.setString(1, "derby.locks.deadlockTimeout");
cstmt.setString(2, "10");
cstmt.execute();
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(cstmt);
JdbcUtils.close(conn);
}
}
use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.
the class PreparedStatementTest method test_pstmt.
@SuppressWarnings("deprecation")
public void test_pstmt() throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt2 = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(create_url);
pstmt = conn.prepareStatement("INSERT INTO T_PRE_STMT_TEST (ID, NAME, BIRTHDATE) VALUES (?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
pstmt.setShort(1, (short) 1);
pstmt.setString(2, "A");
pstmt.setTimestamp(3, new java.sql.Timestamp(System.currentTimeMillis()));
pstmt.execute();
pstmt.setShort(1, (short) 2);
pstmt.setString(2, "B");
pstmt.setNull(3, Types.TIMESTAMP);
pstmt.execute();
pstmt.setShort(1, (short) 3);
pstmt.setString(2, "C");
pstmt.setTimestamp(3, new java.sql.Timestamp(System.currentTimeMillis()), Calendar.getInstance());
pstmt.execute();
pstmt.setShort(1, (short) 3);
pstmt.setString(2, "C");
pstmt.setTimestamp(3, new java.sql.Timestamp(System.currentTimeMillis()), Calendar.getInstance());
try {
pstmt.setArray(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setObject(2, null);
} catch (SQLDataException ex) {
}
try {
pstmt.setNCharacterStream(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setNCharacterStream(2, null, 0L);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setNClob(2, (NClob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setNClob(2, (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setNClob(2, null, 0L);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setNString(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setRef(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setRowId(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setSQLXML(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setURL(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
pstmt.setUnicodeStream(2, null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
pstmt.execute();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = pstmt2.executeQuery();
rs.getCursorName();
rs.clearWarnings();
rs.isBeforeFirst();
rs.isAfterLast();
rs.isFirst();
rs.isLast();
rs.setFetchDirection(rs.getFetchDirection());
rs.setFetchSize(rs.getFetchSize());
rs.getConcurrency();
rs.getRow();
rs.relative(1);
rs.absolute(1);
rs.next();
rs.rowDeleted();
rs.rowInserted();
rs.rowUpdated();
rs.previous();
rs.beforeFirst();
rs.afterLast();
rs.absolute(1);
rs.first();
rs.last();
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = pstmt2.executeQuery();
rs.first();
rs.last();
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
rs = pstmt2.executeQuery();
rs.first();
rs.last();
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", new int[] { 1 });
rs = pstmt2.executeQuery();
JdbcUtils.printResultSet(rs, System.out);
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", new String[] { "ID" });
rs = pstmt2.executeQuery();
JdbcUtils.printResultSet(rs, System.out);
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", new String[] { "ID" });
rs = pstmt2.executeQuery();
try {
rs.getArray(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getArray("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNCharacterStream(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNCharacterStream("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNClob(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNClob("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNString(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getNString("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getRowId(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getRowId("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getSQLXML(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getSQLXML("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
JdbcUtils.printResultSet(rs, System.out);
rs.close();
pstmt2 = conn.prepareStatement("SELECT * FROM T_PRE_STMT_TEST ORDER BY 2", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = pstmt2.executeQuery();
rs.next();
try {
rs.refreshRow();
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.insertRow();
} catch (SQLException ex) {
}
try {
rs.moveToCurrentRow();
} catch (SQLException ex) {
}
try {
rs.moveToInsertRow();
} catch (SQLException ex) {
}
try {
rs.getURL(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getURL("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateArray(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateArray("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNCharacterStream(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNCharacterStream("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNCharacterStream(2, null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNCharacterStream("NAME", null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob(2, (NClob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob("NAME", (NClob) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob(2, (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob("NAME", (Reader) null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob(2, (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNClob("NAME", (Reader) null, 0);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNString(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateNString("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getRef(2);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.getRef("NAME");
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateRef(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateRef("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateRowId(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateRowId("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateSQLXML(2, null);
} catch (SQLFeatureNotSupportedException ex) {
}
try {
rs.updateSQLXML("NAME", null);
} catch (SQLFeatureNotSupportedException ex) {
}
JdbcUtils.printResultSet(rs, System.out);
rs.close();
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(pstmt);
JdbcUtils.close(pstmt2);
JdbcUtils.close(conn);
}
}
use of java.sql.SQLFeatureNotSupportedException 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.SQLFeatureNotSupportedException in project elasticsearch-jdbc by jprante.
the class StandardSource method getConnectionForWriting.
/**
* Get JDBC connection for writing. FOr executing "update", "insert", callable statements
*
* @return the connection
* @throws SQLException when SQL execution gives an error
*/
@Override
public synchronized Connection getConnectionForWriting() throws SQLException {
boolean invalid = writeConnection == null || writeConnection.isClosed();
try {
invalid = invalid || !writeConnection.isValid(5);
} catch (AbstractMethodError e) {
// old/buggy JDBC driver do not implement isValid()
} catch (SQLFeatureNotSupportedException e) {
// Example: postgresql does implement but not support isValid()
}
if (invalid) {
int retries = getRetries();
while (retries > 0) {
retries--;
try {
if (user != null) {
Properties properties = new Properties();
properties.put("user", user);
if (password != null) {
properties.put("password", password);
}
if (getConnectionProperties() != null) {
properties.putAll(getConnectionProperties());
}
writeConnection = DriverManager.getConnection(url, properties);
} else {
writeConnection = DriverManager.getConnection(url);
}
// many drivers don't like autocommit=true
writeConnection.setAutoCommit(getAutoCommit());
return writeConnection;
} catch (SQLNonTransientConnectionException e) {
// ignore derby drop=true silently
} catch (SQLException e) {
context.setThrowable(e);
logger.error("while opening write connection: " + url + " " + e.getMessage(), e);
try {
Thread.sleep(getMaxRetryWait().millis());
} catch (InterruptedException ex) {
// do nothing
}
}
}
}
return writeConnection;
}
Aggregations