Search in sources :

Example 11 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestNchar.

/**
 * test nchar value
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestNchar() throws SQLException {
    String col1Value = "'a'";
    beforeEachSetup("nchar", col1Value);
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + tableName);
    SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
    bulkCopy.setDestinationTableName(destTableName);
    bulkCopy.writeToServer(rs);
    bulkCopy.close();
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
    while (rs.next()) {
        assertEquals("'" + rs.getNString(1).trim() + "'", col1Value);
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 12 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestBitNull.

/**
 * test null value for underlying bit data type
 *
 * @throws SQLException
 */
// TODO: check bitnull
@Test
public void bulkCopyTestBitNull() throws SQLException {
    beforeEachSetup("bit", null);
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + tableName);
    SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
    bulkCopy.setDestinationTableName(destTableName);
    bulkCopy.writeToServer(rs);
    bulkCopy.close();
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
    while (rs.next()) {
        assertEquals(rs.getBoolean(1), false);
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 13 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestTinyint.

/**
 * Test tinyInt value
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestTinyint() throws SQLException {
    int col1Value = 5;
    beforeEachSetup("tinyint", col1Value);
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + tableName);
    SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
    bulkCopy.setDestinationTableName(destTableName);
    bulkCopy.writeToServer(rs);
    bulkCopy.close();
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
    while (rs.next()) {
        assertEquals(rs.getByte(1), 5);
    }
    bulkCopy.close();
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 14 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestInt.

/**
 * Test integer value
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestInt() throws SQLException {
    int col1Value = 5;
    beforeEachSetup("int", col1Value);
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + tableName);
    SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
    bulkCopy.setDestinationTableName(destTableName);
    bulkCopy.writeToServer(rs);
    bulkCopy.close();
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
    while (rs.next()) {
        assertEquals(rs.getInt(1), 5);
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 15 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestSmallmoney.

/**
 * test smallmoney
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestSmallmoney() throws SQLException {
    String col1Value = "126.1230";
    String destTableName = "dest_sqlVariant";
    Utils.dropTableIfExists(tableName, stmt);
    Utils.dropTableIfExists(destTableName, stmt);
    stmt.executeUpdate("create table " + tableName + " (col1 sql_variant)");
    stmt.executeUpdate("INSERT into " + tableName + "(col1) values (CAST (" + col1Value + " AS " + "smallmoney" + ") )");
    stmt.executeUpdate("create table " + destTableName + " (col1 sql_variant)");
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + tableName);
    SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con);
    bulkCopy.setDestinationTableName(destTableName);
    bulkCopy.writeToServer(rs);
    bulkCopy.close();
    rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
    while (rs.next()) {
        assertEquals(rs.getSmallMoney(1), new BigDecimal(col1Value));
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)43 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)34 Test (org.junit.jupiter.api.Test)34 SQLException (java.sql.SQLException)8 ResultSet (java.sql.ResultSet)6 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)5 IOException (java.io.IOException)5 Connection (java.sql.Connection)5 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)4 Statement (java.sql.Statement)4 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)3 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)3 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)3 BigDecimal (java.math.BigDecimal)3 ColumnMap (com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap)1 DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)1 DBTable (com.microsoft.sqlserver.testframework.DBTable)1 SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1