Statement.getLastError Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves the error code returned by the SQL database backend for the last SQL operation.
public:
virtual int getLastError();
public virtual int getLastError ();
abstract member getLastError : unit -> int
override this.getLastError : unit -> int
Public Overridable Function getLastError () As Integer
Returns
The error code returned by the SQL database backend for the last SQL operation; or 0 for success.
Remarks
The following example demonstrates the getLastError method.
static void StatementGetLastError()
{
str sql, sql2;
UserConnection Connection = new UserConnection();
Statement Statement = Connection.createStatement();
boolean clear_infolog = false;
print "-Delete-a-non-existing-record-(valid statement)-----------";
sql = "delete from zipcode where Recid = 2";
new SqlStatementExecutePermission(sql).assert();
Statement.executeUpdate(sql);
print " Error code was: ", Statement.getLastError();
print " Error message was '", Statement.getLastErrorText(), "'";
try
{
print "\n";
print "-Delete-from-a-non-existing-table-(invalid statement)--- --";
sql2 = "delete from StrangeTable07";
new SqlStatementExecutePermission(sql2).assert();
Statement.executeUpdate(sql2);
}
catch (exception::Error)
{
print "Exception was caught:";
print " Error code was: ", Statement.getLastError();
print " Error message was '", Statement.getLastErrorText(), "'";
}
CodeAccessPermission::revertAssert();
pause;
}