How Do You Troubleshoot the Java Program Message “java.sql.SQLException: No database selected”

Problem scenario
Your Java program returns this message: "java.sql.SQLException: No database selected"
What should you do?

Possible Solution #1
Your SQL statement was appropriate for a database but not for the circumstance of connecting to a SQL instance. Try show databases; instead of the SQL you were running.

Possible Solution #2
Did you connect to the SQL instance you thought you connected to? Double check that.

Possible Solution #3
Verify the way your program connects to a database. There may be a syntax error that does not manifest itself until your SQL command is executed.

Leave a comment

Your email address will not be published. Required fields are marked *