Chi*_*led 5 java oracle ddl jdbc resultset
我正在尝试使用JDBC在Oracle 11g数据库上执行DDL语句.我正在使用boolean execute(String SQL)该Statement课程.
以下是执行查询并尝试确定查询结果的代码段:
// 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);
}
}
Run Code Online (Sandbox Code Playgroud)
我不是数据库人,但是有一种情况,DDL语句将无法执行而不会引发SQLException?如果没有,那么我不需要捕获execute方法返回的内容.缺席SQLException表明DDL语句已成功执行.
我正在遵循的教程建议将此方法用于DDL语句:
boolean execute(String SQL) : ....... Use this method to execute SQL DDL statements or when you need to use truly dynamic SQL.
Run Code Online (Sandbox Code Playgroud)
虽然Jdbc文档建议使用int executeUpdate(String sql)执行DDL语句.哪一个在两者中首选?
| 归档时间: |
|
| 查看次数: |
7697 次 |
| 最近记录: |