我写了一个连接器类来连接到 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。为什么?