I am trying to connect DB2 via JDBC. How do I get the output message that sql would have returned as like IDE. Eg Select query would return 100 rows were fetched. Insert would return the number of rows updated.
Also the error messages like no rows found, User does not have privilege to access database, Insert could not be performed due to duplicate primary key etc.
catch
the exception thrown and print the stack trace.
try{
// your SQL work
} catch(Exception e){
e.printStackTrace();
}
This will print the error in your output console.
Use the JDBC api execute update
to get the changed row count. And the exceptions to get other messages.
https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#executeUpdate(java.lang.String)
int executeUpdate(String sql) throws SQLException
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Note:This method cannot be called on a PreparedStatement or CallableStatement.
Parameters: sql - an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
Returns: either the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
Throws: SQLException - if a database access error occurs, this method is called on a closed Statement, the given SQL statement produces a ResultSet object, the method is called on a PreparedStatement or CallableStatement SQLTimeoutException - when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.