Search in sources :

Example 11 with SQLServerStatement

use of com.microsoft.sqlserver.jdbc.SQLServerStatement in project mssql-jdbc by Microsoft.

the class PoolableTest method poolableTest.

/**
 * Poolable Test
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
@Test
@DisplayName("Poolable Test")
public void poolableTest() throws SQLException, ClassNotFoundException {
    try (Connection conn = DriverManager.getConnection(connectionString);
        Statement statement = conn.createStatement()) {
        try {
            // First get the default values
            boolean isPoolable = ((SQLServerStatement) statement).isPoolable();
            assertEquals(isPoolable, false, "SQLServerStatement should not be Poolable by default");
            try (PreparedStatement prepStmt = connection.prepareStatement("select 1")) {
                isPoolable = ((SQLServerPreparedStatement) prepStmt).isPoolable();
                assertEquals(isPoolable, true, "SQLServerPreparedStatement should be Poolable by default");
            }
            try (CallableStatement callableStatement = connection.prepareCall("{  ? = CALL " + "ProcName" + " (?, ?, ?, ?) }")) {
                isPoolable = ((SQLServerCallableStatement) callableStatement).isPoolable();
                assertEquals(isPoolable, true, "SQLServerCallableStatement should be Poolable by default");
                // Now do couple of sets and gets
                ((SQLServerCallableStatement) callableStatement).setPoolable(false);
                assertEquals(((SQLServerCallableStatement) callableStatement).isPoolable(), false, "set did not work");
            }
            ((SQLServerStatement) statement).setPoolable(true);
            assertEquals(((SQLServerStatement) statement).isPoolable(), true, "set did not work");
        } catch (UnsupportedOperationException e) {
            assertEquals(System.getProperty("java.specification.version"), "1.5", "PoolableTest should be supported in anything other than 1.5");
            assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message");
        }
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLServerStatement(com.microsoft.sqlserver.jdbc.SQLServerStatement) PreparedStatement(java.sql.PreparedStatement) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerStatement(com.microsoft.sqlserver.jdbc.SQLServerStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)11 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)5 Connection (java.sql.Connection)5 Test (org.junit.jupiter.api.Test)5 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)3 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ISQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.ISQLServerPreparedStatement)1 SQLServerColumnEncryptionJavaKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider)1 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)1 IOException (java.io.IOException)1