先上测试代码
1 package testJdbc; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.SQLException; 6 7 public class TestJ { 8 9 public static void main(String[] args) { 10 11 try { 12 Class.forName("com.mysql.cj.jdbc.Driver"); 13 @SuppressWarnings("unused") 14 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/members", "Elvis", "Lv636216"); 15 System.out.println("连接成功!"); 16 } catch (ClassNotFoundException e) { 17 e.printStackTrace(); 18 } catch (SQLException e) { 19 e.printStackTrace(); 20 } 21 22 } 23 24 }
如果用jdbc连接MySQL成功,则会在控制台输出连接成功。
runtime error:
解决方法: