import java.sql.*;public class DBTester1 {
   public static void main(String[] args) throws Exception {
   Connection con;
   Statement stmt;
   ResultSet rs;
   
   Class.forName("com.mysql.jdbc.Driver");
   DriverManager.registerDriver(new com.mysql.jdbc.Driver());
   String dbUrl = 
   "jdbc:mysql://localhost:3306/STOREDB?useUnicode=true&characterEncoding=GB2312";
   String dbUser = "dbuser";
   String dbPwd ="1234";
   con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
   stmt= con.createStatement();
   
   stmt.executeUpdate("insert into CUSTOMERS (NAME,AGE,ADDRESS)"
              +"VALUES('小王',20,'上海')");
   rs = stmt.executeQuery("SELECT ID,NAME,AGE,ADDRESS from CUSTOEMRS");
   while(rs.next())
   {
   long id = rs.getLong(1);
   String name = rs.getString(2);
   int age = rs.getInt(3);
   String address = rs.getString(4);
   
   System.out.println("id="+id+",name="+name+",age="+age+",address="+address);
   }
   stmt.executeUpdate("delete from CUSTOMERS where name='小王'");
   rs.close();
   stmt.close();
   con.close();
   }
}package com.mysql.jdbc does not exist, DriverManager.registerDriver(new com.mysql.jdbc.Driver());,这个是什么问题啊,我在里面是加了引号的啊,

解决方案 »

  1.   

    package com.mysql.jdbc does not exist找不到驱动包
    把驱动包引入
      

  2.   

    我引入了啊,在工程——》BUILDPATH>add EXTERNAL archives里面导入了mysqldrvier.jar
      

  3.   

           Class.forName("com.mysql.jdbc.Driver");
           DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    这里重复,驱动只要注册一次就可以了
      

  4.   

    我的驱动包是放在D:/mysql-connector目录下的,而DBTester.java 在D盘的另外一个文件夹下面,这是不是有什么问题?
      

  5.   

    6楼的意思是删掉 DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 
      

  6.   

    驱动包放到这里去试试
    放到   jre\lib\ext\
      

  7.   

    package MidTerm;
    import java.sql.*;public class Conn {    private static Connection con;
        private Statement statement;
        private ResultSet rs;
        private static final String userName = "root";
        private static final String userPassword = "123456";
        private static final String dbName = "hoot";
        private static final String encoding = "characterEncoding=gb2312&useUnicode=true";
        private static final String driveName = "com.mysql.jdbc.Driver";
        private static String url = "jdbc:mysql://localhost/" + dbName + "?" + encoding + "&user=" + userName +
                "&password" + "=" + userPassword;    public static synchronized Connection getCon() throws Exception {
            try {
                Class.forName(driveName).newInstance();
                con =  DriverManager.getConnection(url);
                return con;
            } catch (SQLException e) {
                System.err.println(e.getMessage());
                throw e;
            }
        }    public Statement getStmntRead() {
            try {
                con = getCon();
                statement =  con.createStatement();
                return statement;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
            return null;
        }    public ResultSet getRs(String sql) {
            try {
                statement = getStmntRead();
                rs = statement.executeQuery(sql);
                return rs;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
            return null;
        }    public Statement getStmnt() {
            try {
                con = getCon();
                statement = con.createStatement();
                return statement;
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
            return null;
        }    public synchronized void close() {
            try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
            try {
                if (statement != null) {
                    statement.close();
                    statement = null;
                }
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
            try {
                if (con != null) {
                    con.close();
                    con = null;
                }
            } catch (Exception e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }
    这个事我之前弄的 你对比着看下吧
      

  8.   

    最主要的是你要把那个jar包放在你工程目录的web—inf/lib下
      

  9.   

    应该是mysql的驱动不对或驱动版本和mysql不对应~
      

  10.   

    把驱动包放在web服务器(tomcat)的lib目录下
      

  11.   

    用winrar打开一下mysqldrvier.jar
    查看里面Driver.class有没有在com/mysql/jdbc下面.