测试数据库连接

 1 public static void main(String args[]){  
 2         String url = "jdbc:mysql://localhost:3306/beginssm";  
 3         String driver = "com.mysql.jdbc.Driver";  
 4         try{  
 5             Class.forName(driver);  
 6         }catch(Exception e){  
 7             System.out.println("无法加载驱动");  
 8         }  
 9         try {  
10             Connection con = DriverManager.getConnection(url,"root","123456");  
11             if(!con.isClosed())  
12                 System.out.println("success");  
13         } catch (Exception e) {  
14             e.printStackTrace();  
15         }  
16     }
原文地址:https://www.cnblogs.com/ericguoxiaofeng/p/7633602.html