use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestBinary20.
/**
* test Binary value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestBinary20() throws SQLException {
String col1Value = "hello";
beforeEachSetup("binary(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()));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestDate.
/**
* test date value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestDate() throws SQLException {
String col1Value = "2015-05-05";
beforeEachSetup("date", "'" + 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.getDate(1), col1Value);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyResultSetCursorTest method testMultiplePreparedStatementAndResultSet.
/**
* test with multiple prepared statements and result sets
*
* @throws SQLException
*/
@Test
public void testMultiplePreparedStatementAndResultSet() throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement()) {
dropTables(stmt);
createTables(stmt);
populateSourceTable();
try (ResultSet rs = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE).executeQuery("select * from " + srcTable)) {
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {
bulkCopy.setDestinationTableName(desTable);
bulkCopy.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length);
}
rs.beforeFirst();
try (SQLServerBulkCopy bulkCopy1 = new SQLServerBulkCopy(conn)) {
bulkCopy1.setDestinationTableName(desTable);
bulkCopy1.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length * 2);
}
rs.beforeFirst();
try (SQLServerBulkCopy bulkCopy2 = new SQLServerBulkCopy(conn)) {
bulkCopy2.setDestinationTableName(desTable);
bulkCopy2.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length * 3);
}
String sql = "insert into " + desTable + " values (?,?,?,?)";
Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
try (SQLServerPreparedStatement pstmt1 = (SQLServerPreparedStatement) conn.prepareStatement(sql)) {
for (int i = 0; i < expectedBigDecimals.length; i++) {
pstmt1.setBigDecimal(1, expectedBigDecimals[i]);
pstmt1.setString(2, expectedStrings[i]);
pstmt1.setTimestamp(3, expectedTimestamps[i], calGMT);
pstmt1.setString(4, expectedStrings[i]);
pstmt1.execute();
}
verifyDestinationTableData(expectedBigDecimals.length * 4);
}
try (ResultSet rs2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE).executeQuery("select * from " + srcTable);
SQLServerBulkCopy bulkCopy3 = new SQLServerBulkCopy(conn)) {
bulkCopy3.setDestinationTableName(desTable);
bulkCopy3.writeToServer(rs2);
verifyDestinationTableData(expectedBigDecimals.length * 5);
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyResultSetCursorTest method testSelectMethodSetToCursor.
/**
* Test a previous failure when setting SelectMethod to cursor and using the same connection to create Bulk Copy and result set.
*
* @throws SQLException
*/
@Test
public void testSelectMethodSetToCursor() throws SQLException {
Properties info = new Properties();
info.setProperty("SelectMethod", "cursor");
try (Connection conn = DriverManager.getConnection(connectionString, info);
Statement stmt = conn.createStatement()) {
dropTables(stmt);
createTables(stmt);
populateSourceTable();
try (ResultSet rs = conn.createStatement().executeQuery("select * from " + srcTable);
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {
bulkCopy.setDestinationTableName(desTable);
bulkCopy.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length);
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyResultSetCursorTest method serverCursorsTest.
private void serverCursorsTest(int resultSetType, int resultSetConcurrency) throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement()) {
dropTables(stmt);
createTables(stmt);
populateSourceTable();
try (ResultSet rs = conn.createStatement(resultSetType, resultSetConcurrency).executeQuery("select * from " + srcTable);
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {
bulkCopy.setDestinationTableName(desTable);
bulkCopy.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length);
}
}
}
Aggregations