Search in sources :

Example 21 with SQLServerPreparedStatement

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

the class TVPAllTypes method testTVPResultSet.

private void testTVPResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException {
    setupVariation();
    Connection connnection = null;
    if (setSelectMethod) {
        connnection = DriverManager.getConnection(connectionString + ";selectMethod=cursor;");
    } else {
        connnection = DriverManager.getConnection(connectionString);
    }
    Statement stmtement = null;
    if (null != resultSetType || null != resultSetConcurrency) {
        stmtement = connnection.createStatement(resultSetType, resultSetConcurrency);
    } else {
        stmtement = connnection.createStatement();
    }
    ResultSet rs = stmtement.executeQuery("select * from " + tableSrc.getEscapedTableName());
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connnection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
    pstmt.setStructured(1, tvpName, rs);
    pstmt.execute();
    ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest);
    terminateVariation();
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) Statement(java.sql.Statement) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) ResultSet(java.sql.ResultSet) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)

Example 22 with SQLServerPreparedStatement

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

the class TVPAllTypes method testTVPDataTable.

/**
 * Test TVP with DataTable
 *
 * @throws SQLException
 */
@Test
public void testTVPDataTable() throws SQLException {
    setupVariation();
    SQLServerDataTable dt = new SQLServerDataTable();
    int numberOfColumns = tableDest.getColumns().size();
    Object[] values = new Object[numberOfColumns];
    for (int i = 0; i < numberOfColumns; i++) {
        SqlType sqlType = tableDest.getColumns().get(i).getSqlType();
        dt.addColumnMetadata(tableDest.getColumnName(i), sqlType.getJdbctype().getVendorTypeNumber());
        values[i] = sqlType.createdata();
    }
    int numberOfRows = 10;
    for (int i = 0; i < numberOfRows; i++) {
        dt.addRow(values);
    }
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
    pstmt.setStructured(1, tvpName, dt);
    pstmt.execute();
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SqlType(com.microsoft.sqlserver.testframework.sqlType.SqlType) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 23 with SQLServerPreparedStatement

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

the class TVPNumericTest method testNumericPresicionIssue211.

/**
 * Test a previous failure regarding to numeric precision. Issue #211
 *
 * @throws SQLException
 * @throws SQLTimeoutException
 */
@Test
public void testNumericPresicionIssue211() throws SQLException {
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.NUMERIC);
    tvp.addRow(12.12);
    tvp.addRow(1.123);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + charTable + " select * from ? ;");
    pstmt.setStructured(1, tvpName, tvp);
    pstmt.execute();
    if (null != pstmt) {
        pstmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 24 with SQLServerPreparedStatement

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

the class TVPSchemaTest method testTVPSchemaPreparedInsertCommand.

/**
 * Prepared with InsertCommand
 *
 * @throws SQLException
 * @throws IOException
 */
@Test
@DisplayName("TVPSchemaPreparedInsertCommand")
public void testTVPSchemaPreparedInsertCommand() throws SQLException, IOException {
    SQLServerPreparedStatement P_C_stmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + charTable + " select * from ? ;");
    P_C_stmt.setStructured(1, tvpNameWithSchema, tvp);
    P_C_stmt.executeUpdate();
    rs = stmt.executeQuery("select * from " + charTable);
    verify(rs);
    if (null != P_C_stmt) {
        P_C_stmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with SQLServerPreparedStatement

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

the class TVPIssuesTest method tryTVPPrecisionmissedissue315.

/**
 * Fix an issue: If column is time(x) and TVP is used (with either ResultSet, Stored Procedure or SQLServerDataTable). The milliseconds or
 * nanoseconds are not copied into the destination table.
 *
 * @throws Exception
 */
@Test
public void tryTVPPrecisionmissedissue315() throws Exception {
    setup();
    ResultSet rs = stmt.executeQuery("select * from " + srcTable_time_6);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + desTable_time_6 + " select * from ? ;");
    pstmt.setStructured(1, tvp_time_6, rs);
    pstmt.execute();
    testTime6DestTable();
}
Also used : ResultSet(java.sql.ResultSet) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)43 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)31 Test (org.junit.jupiter.api.Test)31 ResultSet (java.sql.ResultSet)17 SQLServerDataTable (com.microsoft.sqlserver.jdbc.SQLServerDataTable)13 Connection (java.sql.Connection)9 SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)8 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)6 Statement (java.sql.Statement)5 PreparedStatement (java.sql.PreparedStatement)4 Calendar (java.util.Calendar)4 SQLException (java.sql.SQLException)3 DisplayName (org.junit.jupiter.api.DisplayName)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)2 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 Properties (java.util.Properties)2 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)1 SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)1 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)1