use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class RegressionTest method testUpdateQuery.
/**
* Tests update query
*
* @throws SQLException
*/
@Test
public void testUpdateQuery() throws SQLException {
assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. ");
SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
String sql;
SQLServerPreparedStatement pstmt = null;
JDBCType[] targets = { JDBCType.INTEGER, JDBCType.SMALLINT };
int rows = 3;
final String tableName = "[updateQuery]";
Statement stmt = con.createStatement();
Utils.dropTableIfExists(tableName, stmt);
stmt.executeUpdate("CREATE TABLE " + tableName + " (" + "c1 int null," + "PK int NOT NULL PRIMARY KEY" + ")");
/*
* populate table
*/
sql = "insert into " + tableName + " values(" + "?,?" + ")";
pstmt = (SQLServerPreparedStatement) con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability());
for (int i = 1; i <= rows; i++) {
pstmt.setObject(1, i, JDBCType.INTEGER);
pstmt.setObject(2, i, JDBCType.INTEGER);
pstmt.executeUpdate();
}
/*
* Update table
*/
sql = "update " + tableName + " SET c1= ? where PK =1";
for (int i = 1; i <= rows; i++) {
pstmt = (SQLServerPreparedStatement) con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
for (JDBCType target : targets) {
pstmt.setObject(1, 5 + i, target);
pstmt.executeUpdate();
}
}
/*
* Verify
*/
ResultSet rs = stmt.executeQuery("select * from " + tableName);
rs.next();
assertEquals(rs.getInt(1), 8, "Value mismatch");
if (null != stmt)
stmt.close();
if (null != con)
con.close();
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class Wrapper42Test method PreparedSatement42Test.
/**
* Tests creation of SQLServerPreparedSatement42 object
*
* @throws SQLException
*/
@Test
public void PreparedSatement42Test() throws SQLException {
String sql = "SELECT SUSER_SNAME()";
PreparedStatement pstmt = connection.prepareStatement(sql);
if (1.8d <= javaVersion && 4 == major && 2 == minor) {
assertTrue(pstmt instanceof SQLServerPreparedStatement42);
} else {
assertTrue(pstmt instanceof SQLServerPreparedStatement);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class JDBCEncryptionDecryptionTest method testDate.
private void testDate(SQLServerStatement stmt, LinkedList<Object> values1) throws SQLException {
String sql = "select * from " + dateTable;
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try (ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
// testGetStringForDate(rs, numberOfColumns, values1); //TODO: Disabling, since getString throws verification error for zero temporal
// types
testGetObjectForTemporal(rs, numberOfColumns, values1);
testGetDate(rs, numberOfColumns, values1);
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class JDBCEncryptionDecryptionTest method testChar.
private void testChar(SQLServerStatement stmt, String[] values) throws SQLException {
String sql = "select * from " + charTable;
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try (ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, values);
testGetObject(rs, numberOfColumns, values);
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement in project mssql-jdbc by Microsoft.
the class JDBCEncryptionDecryptionTest method testNumeric.
private void testNumeric(Statement stmt, String[] numericValues, boolean isNull) throws SQLException {
String sql = "select * from " + numericTable;
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try (SQLServerResultSet rs = (stmt == null) ? (SQLServerResultSet) pstmt.executeQuery() : (SQLServerResultSet) stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, numericValues);
testGetObject(rs, numberOfColumns, numericValues);
testGetBigDecimal(rs, numberOfColumns, numericValues);
if (!isNull)
testWithSpecifiedtype(rs, numberOfColumns, numericValues);
else {
String[] nullNumericValues = { "false", "0", "0", "0", "0", "0.0", "0.0", "0.0", null, null, null, null, null, null, null, null };
testWithSpecifiedtype(rs, numberOfColumns, nullNumericValues);
}
}
}
}
}
Aggregations