Tomcat 错误:java.sql.SQLException:找不到适合 jdbc:sqlserver:// 的驱动程序

Art*_*s M 4 java tomcat apache-commons-dbcp jdbc-pool

我的 Tomcat 有一个很糟糕的问题,很糟糕,因为这个问题我已经放弃了这个项目一个多月了......但我仍然需要解决它并继续这个项目......

所以它给我这个错误:

java.sql.SQLException:找不到适合 jdbc 的驱动程序:sqlserver://isd.ktu.lt:1433;DatabaseName=LN2012_bakDB2 java.lang.NullPointerException

问题是相同的应用程序在桌面版本 Perfectlz 中运行,但是当涉及到应该在服务器上运行的版本(NetBeans 7.1.2 中的 Tomcat 7.0.22.0)时,它只会抛出错误。似乎它没有加载池驱动程序,或者我什至不知道......

好吧,这是负责的部分:

public DatabaseConnection(Parameters params) {                

    // parameters and the output                
    this.gui = params.getGui();

    // activate database pool
    connectionPool = new GenericObjectPool(null);
    connectionFactory = new DriverManagerConnectionFactory(params.getDbAdr(), params.getDbUser(), params.getDbPass());
    poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    driver = new PoolingDriver();
    driver.registerPool("GenTreeDatabase", connectionPool);
    //driver.registerPool("jdbc:apache:commons:dbcp:GenTreeDatabase", connectionPool);        

}

public void openConn() {
    if (allowOutput) gui.print("Getting connection to database");
    try {
        con = DriverManager.getConnection("jdbc:apache:commons:dbcp:GenTreeDatabase");
        if (con != null) {
            if (allowOutput) gui.print("Connection to database was successful");
        }
    } catch (SQLException ex) {
        gui.err(specificError + "Error getting connection to database - " + ex);
    }
}
Run Code Online (Sandbox Code Playgroud)

它发生在它试图获取连接的地方,然后它得到一个空指针异常,因为连接没有成功检索。

我对 Tomcat 不熟悉,直到现在,Netbeans 对 tomcat 的处理都很好......问题是我讨厌这样的错误......如果你在三天内不解决它,你会很沮丧,不要想回到那个,你感觉就像撞墙......现在我尝试在谷歌上搜索很多,但仍然没有太大帮助......所以如果有人能帮助我我会很高兴这个。谢谢。:)

M. *_*bas 6

您必须将 JDBC 驱动程序的 jar 复制到 $CATALINA_HOME/lib。