I am trying to execute a DDL statement in an Oracle 11g database using JDBC. I do this using a boolean execute(String SQL)class Statement.
The following is a snippet of code that executes a query and tries to determine the result of a query:
String dropSql = "DROP TABLE Reviews";
stmt = conn.createStatement();
boolean result = stmt.execute(dropSql);
if(result)
{
System.out.println("Atleast one result set has been returned. Loop through them");
}
else
{
Integer updateCnt = stmt.getUpdateCount();
if(updateCnt == -1)
{
System.out.println("No results returned by the query");
}
else
{
System.out.println("Update Count: " + updateCnt);
}
}
I am not a database guy, but is there a situation where the DDL statement could not execute and not raise SQLException? If not, then I don't need to commit what the execute method returns. Missing SQLExceptionmeans that the DDL statements succeed.
The tutorial that I follow recommends using this method for DDL statements:
boolean execute(String SQL) : ....... Use this method to execute SQL DDL statements or when you need to use truly dynamic SQL.
Jdbc int executeUpdate(String sql) DDL. ?