use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class BulkCopyResultSetCursorTest method populateSourceTable.
private static void populateSourceTable() throws SQLException {
String sql = "insert into " + srcTable + " values (?,?,?,?)";
Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
try (Connection conn = DriverManager.getConnection(connectionString);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn.prepareStatement(sql)) {
for (int i = 0; i < expectedBigDecimals.length; i++) {
pstmt.setBigDecimal(1, expectedBigDecimals[i]);
pstmt.setString(2, expectedStrings[i]);
pstmt.setTimestamp(3, expectedTimestamps[i], calGMT);
pstmt.setString(4, expectedStrings[i]);
pstmt.execute();
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPSchemaTest method testTVPSchemaPreparedStatementStoredProcedure.
/**
* PreparedStatement with storedProcedure
*
* @throws SQLException
*/
@Test
@DisplayName("TVPSchemaPreparedStatementStoredProcedure()")
public void testTVPSchemaPreparedStatementStoredProcedure() throws SQLException {
final String sql = "{call " + procedureName + "(?)}";
SQLServerPreparedStatement P_C_statement = (SQLServerPreparedStatement) connection.prepareStatement(sql);
P_C_statement.setStructured(1, tvpNameWithSchema, tvp);
P_C_statement.execute();
rs = stmt.executeQuery("select * from " + charTable);
verify(rs);
if (null != P_C_statement) {
P_C_statement.close();
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPIssuesTest method tryTVPRSvarcharMax4000Issue.
@Test
public void tryTVPRSvarcharMax4000Issue() throws Exception {
setup();
SQLServerStatement st = (SQLServerStatement) connection.createStatement();
ResultSet rs = st.executeQuery("select * from " + srcTable_varcharMax);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + desTable_varcharMax + " select * from ? ;");
pstmt.setStructured(1, tvp_varcharMax, rs);
pstmt.execute();
testCharDestTable();
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPIssuesTest method populateCharSrcTable.
private static void populateCharSrcTable() throws SQLException {
String sql = "insert into " + srcTable_varcharMax + " values (?)";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 4001; i++) {
sb.append("a");
}
String value = sb.toString();
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql);
pstmt.setString(1, value);
pstmt.execute();
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class TVPResultSetCursorTest method testSelectMethodSetToCursor.
/**
* Test a previous failure when setting SelectMethod to cursor and using the same connection to create TVP and result set.
*
* @throws SQLException
*/
@Test
public void testSelectMethodSetToCursor() throws SQLException {
Properties info = new Properties();
info.setProperty("SelectMethod", "cursor");
conn = DriverManager.getConnection(connectionString, info);
stmt = conn.createStatement();
dropTVPS();
dropTables();
createTVPS();
createTables();
populateSourceTable();
ResultSet rs = conn.createStatement().executeQuery("select * from " + srcTable);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn.prepareStatement("INSERT INTO " + desTable + " select * from ? ;");
pstmt.setStructured(1, tvpName, rs);
pstmt.execute();
verifyDestinationTableData(expectedBigDecimals.length);
if (null != pstmt) {
pstmt.close();
}
if (null != rs) {
rs.close();
}
}
Aggregations