当前位置: 代码迷 >> Eclipse >> eclipse导入jar包连接mysql数据库出错,帮帮忙~多谢
  详细解决方案

eclipse导入jar包连接mysql数据库出错,帮帮忙~多谢

热度:101   发布时间:2016-04-23 01:19:15.0
eclipse导入jar包连接mysql数据库出错,帮帮忙~谢谢
我用的是jdk1.7
mysql 5.6
在程序中导入mysql-connector-java-5.1.25.jar
百度了很久就是没办法解决,希望大家能帮帮忙~~~,谢谢。
代码是网上提供的,这里引用一下。
http://www.cnblogs.com/fnng/archive/2011/07/18/2110023.html







import java.sql.*;
public class MysqlJdbc {
  public static void main(String args[]) {
    try {
      Class.forName("com.mysql.jdbc.Driver");     //加载MYSQL JDBC驱动程序   
      //Class.forName("org.gjt.mm.mysql.Driver");
     System.out.println("Success loading Mysql Driver!");
    }
    catch (Exception e) {
      System.out.print("Error loading Mysql Driver!");
      e.printStackTrace();
    }
    try {
      Connection connect = DriverManager.getConnection(
          "jdbc:mysql://localhost:3306/test","root","123");
           //连接URL为   jdbc:mysql//服务器地址/数据库名  ,后面的2个参数分别是登陆用户名和密码

      System.out.println("Success connect Mysql server!");
      Statement stmt = connect.createStatement();
      ResultSet rs = stmt.executeQuery("select * from user");
                                                              //user 为你表的名称
      while (rs.next()) {
        System.out.println(rs.getString("name"));
      }
    }
    catch (Exception e) {
      System.out.print("get data error!");
      e.printStackTrace();
    }
  }
}
  相关解决方案