Over the past few days, some users have encountered a known error in the java.sql.sqlexception error code list. This problem can arise for several reasons. Let’s look at them now.
Approved: Fortect
- Introducing SQLException
- Get exceptions
- Receive alerts.
- SQL Categorized Exceptions
- Other SQLException Subclasses
Introducing SQLException
If JDBC encounters an error while interacting with the data source, it will throw a SQLException
as an example, not a exception
. (The data source in this context is the database to which the Connection
element is connected.) SQLException
The instance usually contains the following information, which can help you determine the cause of the error:
-
Description of the error. Get a
String
object containing this description by calling theSQLException.getMessage
tool. -
SQLState code. These codes and their corresponding meanings have been standardized by ISO / ANSI and the Open Group (X / Open), although some restrictions have been left to the database editors to define themselves definitively. This
String
object consists of five alphanumeric characters. Get this mode by calling theSQLException.getSQLState
method. -
Error of laws. This is an error identifying an integer value that caused the
SQLException
instance to be collected. Its meaning and meaning remains implementation specific and may be a valid error code returned by the underlying trader. Get the error by calling the schemaSQLException.getErrorCode
. -
Reason. A
sqlexception
instance can have a causal relationship consisting of it or moreThrowable
objects that resulted in our ownsqlexception
instance being created. ThursdayTo combine these reasons, call mySQLException.getCause
method recursively until a match is found fornull
. -
Link to compound exceptions. If more than one error occurs, they are actually the exceptions that this line refers to. Gets exceptions thrown by the
SQLException.getNextException
method thrown.
Retrieving Exceptions
The following method JDBTCutorialUtilities, .printSQLException
returns SQLState, error code, error description, and reason (if any) that is contained in sqlexception
are contained in As, and any other exceptions are concatenated into:
For example, if you call the course CoffeesTable.dropTable
with Java DB as your DBMS, the COFFEES
table does not exist, in addition to removing the JDBTCutorialUtilities.ignoreSQLException < / code> the output will be something like this:
Instead of printing SQLException
information, you can first get SQLState
and then handle some of the SQLException
as needed. For example, the strategies JDBTCutorialUtilities.ignoreSQLException
in return true
if SQLState
is a version comparable to 42Y55
(and you are using Java DB as your DBMS), which allows JDBTCutorialUtilities.printSQLException
ignore SQLException
:
Receive Warnings
The
SQLWarning
objects are a subclass of SQLException
that controls access to database warnings. Warnings do not halt the task execution, unlike exceptions; simply warning the user that something is not planned. For example, an alert might say that you know the permission you used to revoke has not been revoked.
A can be passed through a Connection
object, one Statement
object (including PreparedStatement
and CallableStatement
) becomes objects) or a ResultSet
object. Each of these classes has a getWarnings
method that buyers must call to see an initial warning about the calling idea. If getWarnings
returns a warning, you can SQLWarning
call the getNextWarning
method to resolve the issue so thatYou will receive additional warnings. Executing a functional instruction automatically removes warnings from the previous functional instruction so that they do not appear. However, this means that you need to be warned about an incredible claim before clients can execute another claim.
The following methods in JDBTCutorialUtilities
show how to populate warning information reported for Statement
ResultSet
objects:
The most common warning is the complete DataTruncation
warning, a subclass of SQLWarning
. All DataTruncation
objects have SQLState 01004
, indicating that there was a problem listening or writing data. With the DataTruncation
methods, most people can know in what order or in what order the parameter data was truncated, if the truncation was represented by a read or write operation, which method would have to be used to transfer many bytes, and how many bytes were actually transferred.
Categorized SQL Exceptions
Your JDBC driver might generate a SQLException
subclass that corresponds to a normal SQLState or general error state that experts believe is not related to a SQLState-specific class value. This allows for more portable error handling code. These exceptions are usually subclasses of one of the future classes:
-
SQLNonTransientException
-
SQLTransientException
-
SQLRecoverableException
Approved: Fortect
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
For more information on these subclasses, see the latest Javadoc in the java.sql
file or the JDBC owner documentation.
Other SQLException Subclasses
-
BatchUpdateException
is thrown if a fatal error occurs during a batch update. In addition to the information provided by theSQLException
process,BatchUpdateException
provides update numbers if any statements that were executed prior to one person's error are taken into account. -
SQLClientInfoException
is thrown when one or more client information properties cannot be setus specifically for the connection. In addition to the information provided bySQLException
,SQLClientInfoException
contains a list of client information properties that have unfortunately not been defined.