/*这是我写的一个java类,照着网上敲的代码,代码内容也理解,用as连接mysql在学习当中,希望大神指点一下, 感激不尽*/ public class renWu { public static void main(String [] args){ Connection conn=null; String driver = "com.mysql.jdbc.Driver";//MySQL 驱动 String url = "jdbc:mysql://localhost:3306/TASK";//MYSQL数据库连接Url String user = "root";//用户名 String password = "123456"; try { Class.forName(driver); try { conn= DriverManager.getConnection(url,user,password); if (conn!=null){ System.out.println("成功"); }else { System.out.println("失败"); } } catch (SQLException e) { e.printStackTrace(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
yanrun
大咪