use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPAllTypes method testTVPResultSet.
private void testTVPResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException {
setupVariation();
Connection connnection = null;
if (setSelectMethod) {
connnection = DriverManager.getConnection(connectionString + ";selectMethod=cursor;");
} else {
connnection = DriverManager.getConnection(connectionString);
}
Statement stmtement = null;
if (null != resultSetType || null != resultSetConcurrency) {
stmtement = connnection.createStatement(resultSetType, resultSetConcurrency);
} else {
stmtement = connnection.createStatement();
}
ResultSet rs = stmtement.executeQuery("select * from " + tableSrc.getEscapedTableName());
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connnection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
pstmt.setStructured(1, tvpName, rs);
pstmt.execute();
ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest);
terminateVariation();
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPAllTypes method testTVPDataTable.
/**
* Test TVP with DataTable
*
* @throws SQLException
*/
@Test
public void testTVPDataTable() throws SQLException {
setupVariation();
SQLServerDataTable dt = new SQLServerDataTable();
int numberOfColumns = tableDest.getColumns().size();
Object[] values = new Object[numberOfColumns];
for (int i = 0; i < numberOfColumns; i++) {
SqlType sqlType = tableDest.getColumns().get(i).getSqlType();
dt.addColumnMetadata(tableDest.getColumnName(i), sqlType.getJdbctype().getVendorTypeNumber());
values[i] = sqlType.createdata();
}
int numberOfRows = 10;
for (int i = 0; i < numberOfRows; i++) {
dt.addRow(values);
}
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
pstmt.setStructured(1, tvpName, dt);
pstmt.execute();
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPNumericTest method testNumericPresicionIssue211.
/**
* Test a previous failure regarding to numeric precision. Issue #211
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testNumericPresicionIssue211() throws SQLException {
tvp = new SQLServerDataTable();
tvp.addColumnMetadata("c1", java.sql.Types.NUMERIC);
tvp.addRow(12.12);
tvp.addRow(1.123);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + charTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, tvp);
pstmt.execute();
if (null != pstmt) {
pstmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPSchemaTest method testTVPSchemaPreparedInsertCommand.
/**
* Prepared with InsertCommand
*
* @throws SQLException
* @throws IOException
*/
@Test
@DisplayName("TVPSchemaPreparedInsertCommand")
public void testTVPSchemaPreparedInsertCommand() throws SQLException, IOException {
SQLServerPreparedStatement P_C_stmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + charTable + " select * from ? ;");
P_C_stmt.setStructured(1, tvpNameWithSchema, tvp);
P_C_stmt.executeUpdate();
rs = stmt.executeQuery("select * from " + charTable);
verify(rs);
if (null != P_C_stmt) {
P_C_stmt.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPIssuesTest method tryTVPPrecisionmissedissue315.
/**
* Fix an issue: If column is time(x) and TVP is used (with either ResultSet, Stored Procedure or SQLServerDataTable). The milliseconds or
* nanoseconds are not copied into the destination table.
*
* @throws Exception
*/
@Test
public void tryTVPPrecisionmissedissue315() throws Exception {
setup();
ResultSet rs = stmt.executeQuery("select * from " + srcTable_time_6);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + desTable_time_6 + " select * from ? ;");
pstmt.setStructured(1, tvp_time_6, rs);
pstmt.execute();
testTime6DestTable();
}
Aggregations