Solutions for SQLException
SQLException can be raised due to multiple reasons in a Java applications. In this Java SQL tutorial, we will see the common reasons and solutions for resolving the SQLException in Java:
1) It may be possible that the JDBC driver being used in your program has not been loaded properly and hence SQLException is being raised. For Oracle, the driver is usually present in classes11.jar or classes12.jar. You need to check with your database to find the appropriate way to get and load the driver.
2) If you are getting access denied as the error message then it could be that you have specified wrong username and password. The username and password information is provided in the connection string used for establishing the connection. Try establishing the connection by using some database client like TOAD with the same user name and password to verify that the database connections are being accepted with correct username and password.
3) Apart from problems with establishing the connections, this exception could be raised when the trying to executing the SQL commands from Java program. The most common error when trying to execute SQL commands is database connection not open. The best solution to avoid this error is to use database connection pooling and get the connection from pool before trying to execute SQL commands.
4) Other reason when the SQLException is raised while trying to run SQL query is due to improper SQL commands which couldn't be executed by the database engine due to syntax errors.