Home  >  Article  >  Database  >  java连不上mysql数据库了= =

java连不上mysql数据库了= =

WBOY
WBOYOriginal
2016-06-06 09:42:161269browse

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 {

<code>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();         }     }     </code>

}

然后提示错误,
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)
,怎么解啊//、

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn