Search in sources :

Example 1 with DBPreparedStatement

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

the class BulkCopyTestSetUp method setUpSourceTable.

/**
 * Create source table needed for testing bulk copy
 * @throws SQLException
 */
@BeforeAll
static void setUpSourceTable() throws SQLException {
    try (DBConnection con = new DBConnection(connectionString);
        DBStatement stmt = con.createStatement();
        DBPreparedStatement pstmt = new DBPreparedStatement(con)) {
        sourceTable = new DBTable(true);
        stmt.createTable(sourceTable);
        pstmt.populateTable(sourceTable);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBPreparedStatement(com.microsoft.sqlserver.testframework.DBPreparedStatement) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with DBPreparedStatement

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

the class bvtTest method testCreatepreparedStatement.

/**
 * Create a preparedStatement, call close
 *
 * @throws SQLException
 */
@Test
public void testCreatepreparedStatement() throws SQLException {
    String colName = table1.getColumnName(7);
    String value = table1.getRowData(7, 0).toString();
    String query = "SELECT * from " + table1.getEscapedTableName() + " where [" + colName + "] = ? ";
    try (DBConnection conn = new DBConnection(connectionString);
        DBPreparedStatement pstmt = conn.prepareStatement(query)) {
        pstmt.setObject(1, new BigDecimal(value));
        DBResultSet rs = pstmt.executeQuery();
        rs.verify(table1);
        rs.close();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBPreparedStatement(com.microsoft.sqlserver.testframework.DBPreparedStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

DBConnection (com.microsoft.sqlserver.testframework.DBConnection)2 DBPreparedStatement (com.microsoft.sqlserver.testframework.DBPreparedStatement)2 DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)1 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)1 DBTable (com.microsoft.sqlserver.testframework.DBTable)1 BigDecimal (java.math.BigDecimal)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1