use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class BulkCopyAllTypes method setupVariation.
private void setupVariation() throws SQLException {
try (DBConnection dbConnection = new DBConnection(connectionString);
DBStatement dbStmt = dbConnection.createStatement()) {
tableSrc = new DBTable(true);
tableDest = tableSrc.cloneSchema();
dbStmt.createTable(tableSrc);
dbStmt.createTable(tableDest);
dbStmt.populateTable(tableSrc);
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class BulkCopyAllTypes method testBulkCopyResultSet.
private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException {
setupVariation();
try (Connection connnection = DriverManager.getConnection(connectionString + (setSelectMethod ? ";selectMethod=cursor;" : ""));
Statement statement = (null != resultSetType || null != resultSetConcurrency) ? connnection.createStatement(resultSetType, resultSetConcurrency) : connnection.createStatement()) {
ResultSet rs = statement.executeQuery("select * from " + tableSrc.getEscapedTableName());
SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connection);
bcOperation.setDestinationTableName(tableDest.getEscapedTableName());
bcOperation.writeToServer(rs);
bcOperation.close();
ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest);
}
terminateVariation();
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class BulkCopyColumnMappingTest method setUpConnection.
/**
* Create connection, statement and generate path of resource file
*/
@BeforeAll
static void setUpConnection() {
con = new DBConnection(connectionString);
stmt = con.createStatement();
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class BulkCopyISQLServerBulkRecordTest method testISQLServerBulkRecord.
@Test
void testISQLServerBulkRecord() throws SQLException {
try (DBConnection con = new DBConnection(connectionString);
DBStatement stmt = con.createStatement()) {
DBTable dstTable = new DBTable(true);
stmt.createTable(dstTable);
BulkData Bdata = new BulkData(dstTable);
BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
BulkCopyTestUtil.performBulkCopy(bulkWrapper, Bdata, dstTable);
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class DateAndTimeTypeTest method testSetup.
@BeforeEach
public void testSetup() throws TestAbortedException, Exception {
try (DBConnection dbc = new DBConnection(connectionString)) {
assumeTrue(9 <= dbc.getServerVersion(), "Aborting test case as SQL Server version does not support TIME");
}
// To get TIME & setTime working on Servers >= 2008, we must add 'sendTimeAsDatetime=false'
// by default to the connection. See issue https://github.com/Microsoft/mssql-jdbc/issues/559
connection = DriverManager.getConnection(connectionString + ";sendTimeAsDatetime=false");
stmt = (SQLServerStatement) connection.createStatement();
Utils.dropTableIfExists("dateandtime", stmt);
String sql1 = "create table dateandtime (id integer not null, my_date date, my_time time, my_timestamp datetime2 constraint pk_esimple primary key (id))";
stmt.execute(sql1);
// add one sample data
String sPrepStmt = "insert into dateandtime (id, my_date, my_time, my_timestamp) values (?, ?, ?, ?)";
pstmt = connection.prepareStatement(sPrepStmt);
pstmt.setInt(1, 42);
pstmt.setDate(2, DATE_TO_TEST);
pstmt.setTime(3, TIME_TO_TEST);
pstmt.setTimestamp(4, TIMESTAMP_TO_TEST);
pstmt.execute();
pstmt.close();
createTVPs("dateTVP", "date");
createTVPs("timeTVP", "time");
createTVPs("timestampTVP", "datetime2");
}
Aggregations