Search in sources :

Example 31 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestVarbinary20.

/**
 * test varbinary value
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestVarbinary20() throws SQLException {
    String col1Value = "hello";
    beforeEachSetup("varbinary(20)", "'" + 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()) {
        assertTrue(Utils.parseByte(rs.getBytes(1), col1Value.getBytes()));
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 32 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestVarbinary8000.

/**
 * test varbinary8000
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestVarbinary8000() throws SQLException {
    String col1Value = "hello";
    beforeEachSetup("binary(8000)", "'" + 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()) {
        assertTrue(Utils.parseByte(rs.getBytes(1), col1Value.getBytes()));
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 33 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestVarChar8000.

/**
 * Read VarChar8000 from SqlVariant
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestVarChar8000() throws SQLException {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8000; i++) {
        buffer.append("a");
    }
    String col1Value = buffer.toString();
    beforeEachSetup("varchar(8000)", "'" + 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.getString(1), col1Value);
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 34 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestSmalldatetime.

/**
 * test smalldatetime
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestSmalldatetime() throws SQLException {
    String col1Value = "2015-05-08 12:26:24";
    beforeEachSetup("smalldatetime", "'" + 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.getSmallDateTime(1), "2015-05-08 12:26:00.0");
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 35 with SQLServerBulkCopy

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

the class BulkCopyWithSqlVariantTest method bulkCopyTestDatetime2.

/**
 * test datetime2
 *
 * @throws SQLException
 */
@Test
public void bulkCopyTestDatetime2() throws SQLException {
    String col1Value = "2015-05-08 12:26:24.12645";
    beforeEachSetup("datetime2(2)", "'" + 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.getTimestamp(1), "2015-05-08 12:26:24.13");
    }
}
Also used : SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy) 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