use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class SQLServerSpatialDatatypeTest method testCheckGeomMetaData.
public void testCheckGeomMetaData() throws SQLException {
beforeEachSetup();
pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geomTableName + " (c1) VALUES (?)");
ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
Geometry g = Geometry.STGeomFromText("POINT (1 2 3 4)", 0);
pstmt.setGeometry(1, g);
pstmt.execute();
int sqlType = paramMetaData.getParameterType(1);
String sqlTypeName = paramMetaData.getParameterTypeName(1);
assertEquals(sqlType, -157);
assertEquals(sqlTypeName, "geometry");
SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geomTableName);
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(rsmd.getColumnType(1), -157);
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetImportedKeys.
/**
* test getImportedKeys() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetImportedKeys() throws SQLException {
SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getImportedKeys(null, null, table1);
validateGetImportedKeysResults(rs1);
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getImportedKeys(catalog, schema, table1);
validateGetImportedKeysResults(rs2);
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getImportedKeys(catalog, "", table1);
validateGetImportedKeysResults(rs3);
try {
dmd.getImportedKeys("", schema, table1);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet 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);
}
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class basicDT method main.
public static void main(String[] args) {
String serverName = null;
String portNumber = null;
String databaseName = null;
String username = null;
String password = null;
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
System.out.print("Enter server name: ");
serverName = br.readLine();
System.out.print("Enter port number: ");
portNumber = br.readLine();
System.out.print("Enter database name: ");
databaseName = br.readLine();
System.out.print("Enter username: ");
username = br.readLine();
System.out.print("Enter password: ");
password = br.readLine();
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://" + serverName + ":" + portNumber + ";" + "databaseName=" + databaseName + ";username=" + username + ";password=" + password + ";";
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
dropAndCreateTable();
insertOriginalData();
System.out.println();
// Create and execute an SQL statement that returns some data
// and display it.
String SQL = "SELECT * FROM " + tableName;
stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(SQL);
rs.next();
displayRow("ORIGINAL DATA", rs);
// Update the data in the result set.
rs.updateInt(1, 200);
rs.updateString(2, "B");
rs.updateString(3, "Some updated text.");
rs.updateBoolean(4, true);
rs.updateDouble(5, 77.89);
rs.updateDouble(6, 1000.01);
long timeInMillis = System.currentTimeMillis();
Timestamp ts = new Timestamp(timeInMillis);
rs.updateTimestamp(7, ts);
rs.updateDate(8, new Date(timeInMillis));
rs.updateTime(9, new Time(timeInMillis));
rs.updateTimestamp(10, ts);
// -480 indicates GMT - 8:00 hrs
((SQLServerResultSet) rs).updateDateTimeOffset(11, DateTimeOffset.valueOf(ts, -480));
rs.updateRow();
// Get the updated data from the database and display it.
rs = stmt.executeQuery(SQL);
rs.next();
displayRow("UPDATED DATA", rs);
}// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null)
try {
rs.close();
} catch (Exception e) {
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
}
if (con != null)
try {
con.close();
} catch (Exception e) {
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerResultSet in project mssql-jdbc by Microsoft.
the class CallableStatementTest method testInputProcedure.
private void testInputProcedure(String sql, String[] values) throws SQLException {
try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setInt(1, Integer.parseInt(values[3]));
if (RandomData.returnZero)
callableStatement.setBigDecimal(2, new BigDecimal(values[8]), 18, 0);
else
callableStatement.setBigDecimal(2, new BigDecimal(values[8]));
callableStatement.setDouble(3, Double.parseDouble(values[5]));
callableStatement.setFloat(4, Float.parseFloat(values[7]));
if (RandomData.returnZero)
// numeric(18,0)
callableStatement.setBigDecimal(5, new BigDecimal(values[10]), 18, 0);
else
// numeric(18,0)
callableStatement.setBigDecimal(5, new BigDecimal(values[10]));
callableStatement.setSmallMoney(6, new BigDecimal(values[12]));
callableStatement.setMoney(7, new BigDecimal(values[13]));
if (values[0].equalsIgnoreCase("true"))
callableStatement.setBoolean(8, true);
else
callableStatement.setBoolean(8, false);
// smallint
callableStatement.setShort(9, Short.parseShort(values[2]));
// bigint
callableStatement.setLong(10, Long.parseLong(values[4]));
// float30
callableStatement.setDouble(11, Double.parseDouble(values[6]));
// decimal(10,5)
callableStatement.setBigDecimal(12, new BigDecimal(values[9]), 10, 5);
// numeric(8,2)
callableStatement.setBigDecimal(13, new BigDecimal(values[11]), 8, 2);
callableStatement.setBigDecimal(14, new BigDecimal(values[14]), 28, 4);
callableStatement.setBigDecimal(15, new BigDecimal(values[15]), 28, 4);
try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
rs.next();
assertEquals(rs.getString(1), values[3], "" + "Test for input parameter fails.\n");
}
} catch (Exception e) {
fail(e.toString());
}
}
Aggregations