use of com.microsoft.sqlserver.jdbc.SQLServerStatement in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method setupVariation.
@BeforeAll
private static void setupVariation() throws SQLException {
conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
SQLServerStatement stmt = (SQLServerStatement) conn.createStatement();
catalog = conn.getCatalog();
schema = conn.getSchema();
connection.createStatement().executeUpdate("if object_id('" + table1 + "','U') is not null drop table " + table1);
connection.createStatement().executeUpdate("if object_id('" + table2 + "','U') is not null drop table " + table2);
stmt.execute("Create table " + table2 + " (c21 int NOT NULL PRIMARY KEY)");
connection.createStatement().executeUpdate("if object_id('" + table3 + "','U') is not null drop table " + table3);
stmt.execute("Create table " + table3 + " (c31 int NOT NULL PRIMARY KEY)");
connection.createStatement().executeUpdate("if object_id('" + table4 + "','U') is not null drop table " + table4);
stmt.execute("Create table " + table4 + " (c41 int NOT NULL PRIMARY KEY)");
connection.createStatement().executeUpdate("if object_id('" + table5 + "','U') is not null drop table " + table5);
stmt.execute("Create table " + table5 + " (c51 int NOT NULL PRIMARY KEY)");
connection.createStatement().executeUpdate("if object_id('" + table1 + "','U') is not null drop table " + table1);
stmt.execute("Create table " + table1 + " (c11 int primary key," + " c12 int FOREIGN KEY REFERENCES " + table2 + "(c21) ON DELETE no action ON UPDATE set default," + " c13 int FOREIGN KEY REFERENCES " + table3 + "(c31) ON DELETE cascade ON UPDATE set null," + " c14 int FOREIGN KEY REFERENCES " + table4 + "(c41) ON DELETE set null ON UPDATE cascade," + " c15 int FOREIGN KEY REFERENCES " + table5 + "(c51) ON DELETE set default ON UPDATE no action," + ")");
}
use of com.microsoft.sqlserver.jdbc.SQLServerStatement in project mssql-jdbc by Microsoft.
the class TVPIssuesTest method testExceptionWithInvalidStoredProcedureName.
/**
* Test exception when invalid stored procedure name is used.
*
* @throws Exception
*/
@Test
public void testExceptionWithInvalidStoredProcedureName() throws Exception {
SQLServerStatement st = (SQLServerStatement) connection.createStatement();
ResultSet rs = st.executeQuery("select * from " + srcTable_varcharMax);
dropProcedure();
final String sql = "{call " + spName_varcharMax + "(?)}";
SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql);
try {
Cstmt.setObject(1, rs);
throw new Exception("Expected Exception for invalied stored procedure name is not thrown.");
} catch (Exception e) {
if (e instanceof SQLException) {
assertTrue(e.getMessage().contains("Could not find stored procedure"), "Invalid Error Message.");
} else {
throw e;
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerStatement 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.SQLServerStatement in project mssql-jdbc by Microsoft.
the class WrapperTest method unWrapFailureTest.
/**
* Tests expected unwrapper failures
* @throws Exception
*/
@Test
public void unWrapFailureTest() throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(connectionString);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement();
try {
String str = "java.lang.String";
boolean isWrapper = stmt.isWrapperFor(Class.forName(str));
stmt.unwrap(Class.forName(str));
assertEquals(isWrapper, false, "SQLServerStatement should not be a wrapper for string");
stmt.unwrap(Class.forName(str));
assertTrue(false, "An exception should have been thrown. This code should not be reached");
} catch (SQLException ex) {
Throwable t = ex.getCause();
Class exceptionClass = Class.forName("java.lang.ClassCastException");
assertEquals(t.getClass(), exceptionClass, "The cause in the exception class does not match");
} catch (UnsupportedOperationException e) {
assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor should be supported in anything other than 1.5");
assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message");
} finally {
if (null != stmt) {
stmt.close();
}
if (null != con) {
con.close();
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerStatement in project mssql-jdbc by Microsoft.
the class BatchExecutionWithNullTest method terminateVariation.
@AfterAll
public static void terminateVariation() throws SQLException {
connection = DriverManager.getConnection(connectionString);
SQLServerStatement stmt = (SQLServerStatement) connection.createStatement();
Utils.dropTableIfExists("esimple", stmt);
if (null != pstmt) {
pstmt.close();
}
if (null != pstmt1) {
pstmt1.close();
}
if (null != stmt) {
stmt.close();
}
if (null != rs) {
rs.close();
}
if (null != connection) {
connection.close();
}
}
Aggregations