Search in sources :

Example 1 with SQLServerConnection

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

the class ConnectionDriverTest method testAbort.

@Test
public void testAbort() throws SQLException {
    SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
    Executor executor = Executors.newFixedThreadPool(2);
    conn.abort(executor);
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) Executor(java.util.concurrent.Executor) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 2 with SQLServerConnection

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

the class ConnectionDriverTest method testIsWrapperFor.

@Test
public void testIsWrapperFor() throws SQLException, ClassNotFoundException {
    try (Connection conn = DriverManager.getConnection(connectionString);
        SQLServerConnection ssconn = (SQLServerConnection) conn) {
        boolean isWrapper;
        isWrapper = ssconn.isWrapperFor(ssconn.getClass());
        assertTrue(isWrapper, "SQLServerConnection supports unwrapping");
        assertEquals(ssconn.TRANSACTION_SNAPSHOT, ssconn.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT ");
        isWrapper = ssconn.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection"));
        assertTrue(isWrapper, "ISQLServerConnection supports unwrapping");
        ISQLServerConnection iSql = (ISQLServerConnection) ssconn.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection"));
        assertEquals(iSql.TRANSACTION_SNAPSHOT, iSql.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT ");
        ssconn.unwrap(Class.forName("java.sql.Connection"));
    }
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 3 with SQLServerConnection

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

the class ConnectionDriverTest method testClosedConnection.

@Test
public void testClosedConnection() throws SQLException {
    SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
    conn.close();
    assertTrue(!conn.isValid(0), "Closed connection should be invalid");
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 4 with SQLServerConnection

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

the class ConnectionDriverTest method testDeadConnection.

@Test
public void testDeadConnection() throws SQLException {
    assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL.");
    try (SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString + ";responseBuffering=adaptive")) {
        Statement stmt = null;
        String tableName = RandomUtil.getIdentifier("Table");
        tableName = DBTable.escapeIdentifier(tableName);
        conn.setAutoCommit(false);
        stmt = conn.createStatement();
        stmt.executeUpdate("CREATE TABLE " + tableName + " (col1 int primary key)");
        for (int i = 0; i < 80; i++) {
            stmt.executeUpdate("INSERT INTO " + tableName + "(col1) values (" + i + ")");
        }
        conn.commit();
        try {
            stmt.execute("SELECT x1.col1 as foo, x2.col1 as bar, x1.col1 as eeep FROM " + tableName + " as x1, " + tableName + " as x2; RAISERROR ('Oops', 21, 42) WITH LOG");
        } catch (SQLException e) {
            assertEquals(e.getMessage(), "Connection reset", "Unknown Exception");
        } finally {
            DriverManager.getConnection(connectionString).createStatement().execute("drop table " + tableName);
        }
        assertEquals(conn.isValid(5), false, "Dead connection should be invalid");
    }
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) SQLException(java.sql.SQLException) Statement(java.sql.Statement) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 5 with SQLServerConnection

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

the class ConnectionDriverTest method testGetSchema.

@Test
public void testGetSchema() throws SQLException {
    SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
    conn.getSchema();
}
Also used : SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Aggregations

SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)25 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)19 Test (org.junit.jupiter.api.Test)19 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)8 SQLException (java.sql.SQLException)8 ISQLServerConnection (com.microsoft.sqlserver.jdbc.ISQLServerConnection)7 Statement (java.sql.Statement)5 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)3 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 BatchUpdateException (java.sql.BatchUpdateException)2 Properties (java.util.Properties)2 SQLServerColumnEncryptionJavaKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider)1 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)1 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Connection (java.sql.Connection)1 JDBCType (java.sql.JDBCType)1