• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname

 
aavik kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This program i stored as MySQLConnectExample.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class MySQLConnectExample {
public static void main(String[] args) {

// creates three different Connection objects
Connection conn1 = null;
Connection conn2 = null;
Connection conn3 = null;

try {
// connect way #1
String url1 = "jdbc:mysql://localhost:3306/aavikme";
String user = "root";
String password = "aa";

conn1 = DriverManager.getConnection(url1, user, password);
if (conn1 != null) {
System.out.println("Connected to the database test1");
}

// connect way #2
String url2 = "jdbc:mysql://localhost:3306/aavikme?user=root&password=aa";
conn2 = DriverManager.getConnection(url2);
if (conn2 != null) {
System.out.println("Connected to the database test2");
}

// connect way #3
String url3 = "jdbc:mysql://localhost:3306/aavikme";
Properties info = new Properties();
info.put("user", "root");
info.put("password", "aa");

conn3 = DriverManager.getConnection(url3, info);
if (conn3 != null) {
System.out.println("Connected to the database test3");
}
} catch (SQLException ex) {
System.out.println("An error occurred. Maybe user/password is invalid");
ex.printStackTrace();
}
}
}

i run the program through cmd
like this
E:\java mysql code driver>javac MySQLConnectExample.java

E:\java mysql code driver>java -cp mysql-connector-java-3.0.11-stable-bin.jar;.
MySQLConnectExample
An error occurred. Maybe user/password is invalid
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
aavikme
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at MySQLConnectExample.main(MySQLConnectExample.java:20)

This is how i stored my file
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you install Connector/J ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic