In JDBC, how do I know if a DDL statement has been executed successfully?

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:

// Create a SQL string
String dropSql = "DROP TABLE Reviews";

stmt = conn.createStatement();

// Execute the query
boolean result = stmt.execute(dropSql);

// Get the result of the drop operation
if(result)
{
    // Its a result set
    System.out.println("Atleast one result set has been returned. Loop through them");
}
else
{
    // Its an update count or no result
    Integer updateCnt = stmt.getUpdateCount();

    if(updateCnt == -1)
    {
        // No results
        System.out.println("No results returned by the query");
    }
    else
    {
        // Update Count 
        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. ?

+4
2

SQLException , . executeUpdate , ResultSet, DDL.

+4

DDL PL/QSL , JDBC.

, , DDL .

DDL " ", DML, try/catch , .

+3

All Articles