packagetest;importjava.*;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importstaticjava.lang.System.out;publicclassTeacher{publicstat...
package test;
import java.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import static java.lang.System.out;
public class Teacher {
public static void main(String[]args)
throws ClassNotFoundException,SQLException{
Class.forName("com.mysql.jdbc.Driver");
//jdbc:mysql://localhost:8080/test_book?user=root&password=123456";
String url = "jabc:mysql://localhost:3306/test";
String user = "root";
String password = "123456";
//Connection conn = null;
//SQLException ex = null;
try(
Connection conn = DriverManager.getConnection(url, user, password)){
out.printf("已%s数据库联机%n",conn.isClosed()?"关闭":"开启");
}
//System.out.println("Hello Word");
}
}
Exception in thread "main" java.sql.SQLException: No suitable driver found for jabc:mysql://localhost:3306/test
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at test.Teacher.main(Teacher.java:24)
展开