当前位置:Gxlcms > mysql > java连不上mysql数据库了==

java连不上mysql数据库了==

时间:2021-07-01 10:21:17 帮助过:38人阅读

mysqljava数据库

代码如下
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;

public class mysql {

public static void main(String[] args) {    String driver = "com.mysql.jdbc.Driver";      // URL指向要访问的数据库名    String url = "jdbc:mysql://localhost:3306/test";      // MySQL配置时的用户名      String user = "root";      // Java连接MySQL配置时的密码      String password = "123456";      try {          // 加载驱动程序          Class.forName(driver);          // 连续数据库          Connection conn = DriverManager.getConnection(url, user, password);          if(!conn.isClosed())          System.out.println("Succeeded connecting to the Database!");      } catch(ClassNotFoundException e) {             System.out.println("Sorry,can`t find the Driver!");             e.printStackTrace();         } catch(SQLException e) {             e.printStackTrace();         } catch(Exception e) {             e.printStackTrace();         }     }     

}

然后提示错误,
Sorry,can`t find the Driver!
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at mysql.main(mysql.java:25)
,怎么解啊//、

人气教程排行