use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestNvarchar.
/**
* test nvarchar value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestNvarchar() throws SQLException {
String col1Value = "'hello'";
beforeEachSetup("nvarchar", 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).trim() + "'", col1Value);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestVarchar.
/**
* test varchar value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestVarchar() throws SQLException {
String col1Value = "'hello'";
beforeEachSetup("varchar", 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).trim() + "'", col1Value);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestTime.
/**
* test time
*
* @throws SQLException
*/
@Test
public void bulkCopyTestTime() throws SQLException {
String col1Value = "'12:26:27.1452367'";
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 " + "time(2)" + ") )");
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);
rs = (SQLServerResultSet) stmt.executeQuery("SELECT * FROM " + destTableName);
rs.next();
assertEquals("" + rs.getObject(1).toString(), "12:26:27");
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestFloat.
/**
* test float value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestFloat() throws SQLException {
int col1Value = 5;
beforeEachSetup("float", 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.getDouble(1), col1Value);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerBulkCopy in project mssql-jdbc by Microsoft.
the class BulkCopyWithSqlVariantTest method bulkCopyTestTimeWithScale.
/**
* test time with scale value
*
* @throws SQLException
*/
@Test
public void bulkCopyTestTimeWithScale() throws SQLException {
String col1Value = "'12:26:27.1452367'";
beforeEachSetup("time(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()) {
// getTime does not work
assertEquals("" + rs.getString(1), "12:26:27.15");
}
}
Aggregations