myeclipse不识别Class.forName("com.mysql.jdbc.Driver")
问题是有个javaweb项目用到jbdc可以使用自学很苦逼,忘大神给解决一下

解决方案 »

  1.   

    你能把代码发全么?你能说下  你放好mysql的驱动jar包了么
      

  2.   

    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
      

  3.   

    public class DBUtil {
    try {
    Class.forName("com.mysql.jdbc.Dirver");
    } catch (ClassNotFoundException e) {}
    public static Connection getCon()throws Exception{
    String url = "jdbc:mysql://localhost:3306/search?useUnicode=true&characterEncoding=utf8";
    Connection con = DriverManager.getConnection(url,"root","root");
    return con;
    }
    }
      

  4.   

    感觉就是 驱动jar 没有 导入   楼主 导入jar报了吗百分之八十就这个问题!!!
      

  5.   

    Class.forName("com.mysql.jdbc.Dirver");  这句话为啥不识别  代码在楼上
      

  6.   


    我不是很懂但我这3个jar包都导入了
      

  7.   

    这些jar要放到WEB-INF下的那个lib文件下
      

  8.   


    try {
    Class.forName("com.mysql.jdbc.Dirver");
    } catch (ClassNotFoundException e) {}
    你就直接放类里面了 都没放方法里 可以这么放么
      

  9.   

    public class JdbcUtil { private static final String url = "jdbc:mysql://localhost:3306/dbdemo?useUnicode=true&characterEncoding=UTF-8";
    private static final String user = "root";
    private static final String password = "sa"; private static ThreadLocal<Connection> connectionContainer = new ThreadLocal<Connection>(); /**
     * 注册
     * 
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static Connection register() {
    Connection connection = connectionContainer.get();
    try {
    if (connection == null) {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    connection = DriverManager.getConnection(url, user, password);
    }
    connectionContainer.set(connection);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return connection;
    } public static void freeResource(Statement statement, ResultSet rs) {
    try {
    if (rs != null) {
    rs.close();
    }
    if (statement != null) {
    statement.close();
    }
    Connection connection = connectionContainer.get();
    if (connection != null) {
    connection.close();
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    connectionContainer.remove();
    }
    }
    }
      

  10.   

    楼主可以选中导入的那三个jar包
    然后右键 build path  
    这样就可以了!!!!!