错误:无法加载JDBC驱动程序 - org.hsqldb.jdbcDriver

时间:2012-09-21 15:26:04

标签: java database eclipse hsqldb

我写了一个连接器类来连接到hsqldb。

这是我的代码:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;


public class hsqlmanager {

        private static final Logger log = Logger.getLogger(hsqlmanager.class);

        private static Connection con=null;

        private static void openConnection(){
            try {
                Class.forName("org.hsqldb.jdbcDriver" );
                log.info("Loaded JDBC Driver");
            } 
            catch (Exception e) {
                log.error("ERROR: failed to load JDBC driver - " + e.getMessage());
                return;
            }

            try {
                con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/sepm_db","sa","");      
            }
            catch(SQLException e){
                log.error(e.getMessage());
            }
        }

        public static void closeConnection() {
            try {
                con.close();
            }
            catch(SQLException e) {
                log.error(e.getMessage());
            }
        }

        public static Connection getConnection() {
            if (con==null){
                openConnection();
            }
            else {
                try {
                if(con.isClosed()){
                    con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/sepm_db","sa","");

                }
                }
                catch(SQLException e){
                    log.error(e.getMessage());
                    return null;
                }
            }

            return con;
        }

}

当我编译时,我得到错误:无法加载JDBC驱动程序 - org.hsqldb.jdbcDriver。为什么呢?

1 个答案:

答案 0 :(得分:2)

您需要下载hsqldb并在类路径中提供。驱动程序位于zip文件中。