今天用jdbc写了一句sql语句,通过PreparedStatement对象来插入记录,发现一个奇怪的问题,我明明是成功插入记录,可是pstmt.execute()确返回的是false,狂晕中。
- String
sqlText = "insert into problem(title, " + -
"description, input, output, sample_input, " + -
"sample_output, hint, source, uploader) " + -
"values(?, ?, ?, ?, ?, ?, ?, ?, ?)"; -
PreparedStatement pstmt = null; - ......
- res
= pstmt.execute();
sun API 写道
public boolean execute()
throws SQLExceptionExecutes the SQL statement in thisPreparedStatement object, which may be any kind of SQL statement.Some prepared statements return multiple results; the executemethod handles these complex statements as well as the simpler formof statements handled by the methods executeQuery andexecuteUpdate.
The execute method returns a boolean to indicate the form of thefirst result. You must call either the method getResultSet orgetUpdateCount to retrieve the result; you must call getMoreResultsto move to any subsequent result(s).
Returns:
true if the first result is a ResultSet object; false if the firstresult is an update count or there is no result
Throws:
SQLException - if a database access error occurs or an argument issupplied to this method
throws SQLExceptionExecutes the SQL statement in thisPreparedStatement object, which may be any kind of SQL statement.Some prepared statements return multiple results; the executemethod handles these complex statements as well as the simpler formof statements handled by the methods executeQuery andexecuteUpdate.
The execute method returns a boolean to indicate the form of thefirst result. You must call either the method getResultSet orgetUpdateCount to retrieve the result; you must call getMoreResultsto move to any subsequent result(s).
Returns:
true if the first result is a ResultSet object; false if the firstresult is an update count or there is no result
Throws:
SQLException - if a database access error occurs or an argument issupplied to this method