Resolving "No Database Selected" Error in MySQL Website Retrieval
When attempting to retrieve data from a MySQL database hosted on a website (e.g., GoDaddy), you may encounter the "java.sql.SQLException: No database selected" error. This error indicates that the database URL you are using in your JDBC connection does not specify the database name.
The correct format for your database URL in Java is:
jdbc:mysql://host:port/databaseName
In your provided code, you have:
String DB_URL = "jdbc:mysql://localhost:3306/";
This URL does not include your database name. To resolve the issue, you should specify the database name in the URL. For example:
String DB_URL = "jdbc:mysql://localhost:3306/mydb";
Replace "mydb" with the actual name of your database. Once you have updated the database name in the URL, try retrieving data from your database again. The error should now be resolved.
The above is the detailed content of Why Am I Getting the \'No Database Selected\' Error in My MySQL Website Retrieval?. For more information, please follow other related articles on the PHP Chinese website!