- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Resolve java.sql.SQLException: No suitable driver found for localhost test?
You will get this type of exception whenever your JDBC URL is not accepted by any of the loaded JDBC drivers by the method acceptsURL. You need to mention the MySQL JDBC driver which is as follows −
The MySQL JDBC url is as follows −
jdbc:mysql://localhost:3306/test?useSSL=false
The prototype of acceptsURL is as follows −
boolean acceptsURL(String url) throws SQLException
The acceptsURL returns boolean that means if the JDBC driver understands the database URL it returns true otherwise false. It takes one parameter of type String which is a database URL.
The entire database URL connection is as follows. The syntax −
con = DriverManager. getConnection("jdbc:mysql://localhost:3306/yourDatabaseName?useSSL=false", "yourUserName", " yourPassword");
Example
The Java code is as follows −
import java.sql.Connection; import java.sql.DriverManager; public class AvoidSQLException { public static void main(String[]args){ Connection con = null; try { con = DriverManager. getConnection("jdbc:mysql://localhost:3306/sample?useSSL=false", "root", "123456"); System.out.println("Connection is successful !!!!!"); } catch(Exception e) { e.printStackTrace(); } } }
Output
The snapshot of code is as follows −
The following is the output −
Connection is successful !!!!!
The snapshot of the sample code is as follows −
Advertisements
To Continue Learning Please Login
Login with Google