连接到本地数据库时出错(java)

时间:2014-03-27 00:20:46

标签: java mysql database connection local

我正在使用xampp控制面板v3.1.0,我已将数据库导入myphpadmin,我正在尝试连接到我的本地数据库山姆但我不知道为什么我一直收到以下错误:

 java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at system.DBConnector.connect(DBConnector.java:28)


public class DBConnector {
        public static final String URL = "jdbc:mysql://localhost:3306/";
        public static final String DATABASE = "sam";
        public static final String DRIVER = "org.gjt.mm.mysql.Driver";
        public static final String USERNAME = "";
        public static final String PASSWORD = "";
        private static Connection connection = null;
        private static Statement statement = null;
        private static PreparedStatement preparedStatement = null;
        private static ResultSet resultSet = null;

        /** Open database connection to a specified database */
        protected void connect() {
            try {
                Class.forName(DRIVER).newInstance();
                connection = DriverManager.getConnection(URL+DATABASE,USERNAME,PASSWORD);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

0 个答案:

没有答案