Search in sources :

Example 1 with SQLServerException

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

the class SQLVariantResultSetTest method insertVarChar8001.

/**
 * Testing that inserting value more than 8000 on varchar(8000) should throw failure operand type clash
 *
 * @throws SQLException
 */
@Test
public void insertVarChar8001() throws SQLException {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8001; i++) {
        buffer.append("a");
    }
    Utils.dropTableIfExists(tableName, stmt);
    stmt.executeUpdate("create table " + tableName + " (col1 sql_variant)");
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement("insert into " + tableName + " values (?)");
    pstmt.setObject(1, buffer.toString());
    try {
        pstmt.execute();
    } catch (SQLServerException e) {
        assertTrue(e.toString().contains("com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash"));
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 2 with SQLServerException

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

the class SSLProtocolTest method testWithSupportedProtocols.

/**
 * Connect with supported protocol
 *
 * @param sslProtocol
 * @throws Exception
 */
public void testWithSupportedProtocols(String sslProtocol) throws Exception {
    String url = connectionString + ";sslProtocol=" + sslProtocol;
    try {
        con = DriverManager.getConnection(url);
        DatabaseMetaData dbmd = con.getMetaData();
        assertNotNull(dbmd);
        assertTrue(!StringUtils.isEmpty(dbmd.getDatabaseProductName()));
    } catch (SQLServerException e) {
        // Some older versions of SQLServer might not have all the TLS protocol versions enabled.
        // Example, if the highest TLS version enabled in the server is TLSv1.1,
        // the connection will fail if we enable only TLSv1.2
        assertTrue(e.getMessage().contains("protocol version is not enabled or not supported by the client."));
    }
}
Also used : SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) DatabaseMetaData(java.sql.DatabaseMetaData)

Aggregations

SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)2 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)1 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Test (org.junit.jupiter.api.Test)1