Common JDBC errors and solutions

Common JDBC errors and solutions

1. ClassNotFoundException

Insert picture description here

  • Analysis: The exception message indicates that the class cannot be found. The reason is that oracle.jdbc.OracleDriver is not loaded into the JVM. It may be because the JDBC driver jar package is not imported, or the parameters of the loaded driver are written incorrectly.
  • Solution: Check whether the JDBC driver jar package is imported in the project, or check whether the loaded driver parameters are correct.
2. SQLException: No suitable driver found for jdbc:orale:thin:@localhost:1521:xe
  • Reason: the url is wrong
  • Solution: carefully check your program url
3. SQLException: Listener refused the connection with the following error:xxxxx
  • Reason: the url is still wrong
4. SQLException: IO 错误: The Network Adapter could not establish the connection
  • Reason: The IP address in the URL is wrong, or there is a problem with the oracle service
5. SQLException: IO 错误: Invalid number format for port number
  • Reason: There is a problem with the port in the URL.
6. SQLException: ORA-01017: invalid username/password; logon denied
  • Reason: The user name or password is wrong.
7. SQLException: Identifier is invalid/table or view does not exist/too many values/columns are not allowed here/missing from …, and locate the error row through the exception stack information, and locate stm.executeXX(sql)
  • Reason: sql statement is wrong
  • Common phenomena:
    a. Table or view does not exist: there is no table name or view name in sql in the library table
    Insert picture description here
    b. Invalid class name: there is no column to be operated on in the table
    Insert picture description here
    c. Invalid character: SQL syntax has problems
    Insert picture description here
    above Problem source code case show: there is a semicolon in sql
    Insert picture description here
8. Properties cannot load configuration file

Insert picture description here

  • Analysis: The exception is a null pointer exception. The exception prompt shows that there is a problem with line 33 of JDBCUtils.java, the load load error, and the input stream transmitted in the load method is empty, that is, the configuration file information is not obtained.
  • Solution: Check whether the path of the configuration file is correct.
    Insert picture description here
9. The database connection is null

Insert picture description here

  • Problem analysis: When jdbc is connecting to the database, if the database connection object conn used has been closed, this error will be reported
  • Solution:
    a. Make sure that the database connection is not closed in dao, and hand it over to the business layer to close the database connection
    . b. After making sure to close the database connection in the jdbc tool class, remove the current database connection from the current thread
10. JDBC can not find the data in the database
  • Problem description: Through the database interface or plsqldev (database operation tool) to query multiple data in the operation table, but the query result of connecting to the database through jdbc is inconsistent with the database result (the number of entries is small)
  • Reason analysis:
    a. First determine whether the database connected by jdbc and the database connected by plsqldev are the same database
    b. Determine whether the data viewed in plsqldev is in the rollback segment, that is, whether the transaction is not committed
  • Solution: Ensure that jdbc and plsqldev are connected to the same database. Ensure that the transaction has been committed.

Guess you like

Origin blog.csdn.net/Java_lover_zpark/article/details/89981585