Search in sources :

Example 6 with SQLServerPreparedStatement

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

the class BulkCopyResultSetCursorTest method populateSourceTable.

private static void populateSourceTable() throws SQLException {
    String sql = "insert into " + srcTable + " values (?,?,?,?)";
    Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    try (Connection conn = DriverManager.getConnection(connectionString);
        SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn.prepareStatement(sql)) {
        for (int i = 0; i < expectedBigDecimals.length; i++) {
            pstmt.setBigDecimal(1, expectedBigDecimals[i]);
            pstmt.setString(2, expectedStrings[i]);
            pstmt.setTimestamp(3, expectedTimestamps[i], calGMT);
            pstmt.setString(4, expectedStrings[i]);
            pstmt.execute();
        }
    }
}
Also used : Calendar(java.util.Calendar) Connection(java.sql.Connection) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)

Example 7 with SQLServerPreparedStatement

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

the class TVPSchemaTest method testTVPSchemaPreparedStatementStoredProcedure.

/**
 * PreparedStatement with storedProcedure
 *
 * @throws SQLException
 */
@Test
@DisplayName("TVPSchemaPreparedStatementStoredProcedure()")
public void testTVPSchemaPreparedStatementStoredProcedure() throws SQLException {
    final String sql = "{call " + procedureName + "(?)}";
    SQLServerPreparedStatement P_C_statement = (SQLServerPreparedStatement) connection.prepareStatement(sql);
    P_C_statement.setStructured(1, tvpNameWithSchema, tvp);
    P_C_statement.execute();
    rs = stmt.executeQuery("select * from " + charTable);
    verify(rs);
    if (null != P_C_statement) {
        P_C_statement.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 8 with SQLServerPreparedStatement

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

the class TVPIssuesTest method tryTVPRSvarcharMax4000Issue.

@Test
public void tryTVPRSvarcharMax4000Issue() throws Exception {
    setup();
    SQLServerStatement st = (SQLServerStatement) connection.createStatement();
    ResultSet rs = st.executeQuery("select * from " + srcTable_varcharMax);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + desTable_varcharMax + " select * from ? ;");
    pstmt.setStructured(1, tvp_varcharMax, rs);
    pstmt.execute();
    testCharDestTable();
}
Also used : ResultSet(java.sql.ResultSet) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerStatement(com.microsoft.sqlserver.jdbc.SQLServerStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 9 with SQLServerPreparedStatement

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

the class TVPIssuesTest method populateCharSrcTable.

private static void populateCharSrcTable() throws SQLException {
    String sql = "insert into " + srcTable_varcharMax + " values (?)";
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 4001; i++) {
        sb.append("a");
    }
    String value = sb.toString();
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql);
    pstmt.setString(1, value);
    pstmt.execute();
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)

Example 10 with SQLServerPreparedStatement

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

the class TVPResultSetCursorTest method testSelectMethodSetToCursor.

/**
 * Test a previous failure when setting SelectMethod to cursor and using the same connection to create TVP and result set.
 *
 * @throws SQLException
 */
@Test
public void testSelectMethodSetToCursor() throws SQLException {
    Properties info = new Properties();
    info.setProperty("SelectMethod", "cursor");
    conn = DriverManager.getConnection(connectionString, info);
    stmt = conn.createStatement();
    dropTVPS();
    dropTables();
    createTVPS();
    createTables();
    populateSourceTable();
    ResultSet rs = conn.createStatement().executeQuery("select * from " + srcTable);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn.prepareStatement("INSERT INTO " + desTable + " select * from ? ;");
    pstmt.setStructured(1, tvpName, rs);
    pstmt.execute();
    verifyDestinationTableData(expectedBigDecimals.length);
    if (null != pstmt) {
        pstmt.close();
    }
    if (null != rs) {
        rs.close();
    }
}
Also used : ResultSet(java.sql.ResultSet) SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Properties(java.util.Properties) 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