1. <small id='rDddk'></small><noframes id='rDddk'>

    <legend id='rDddk'><style id='rDddk'><dir id='rDddk'><q id='rDddk'></q></dir></style></legend>
      • <bdo id='rDddk'></bdo><ul id='rDddk'></ul>

      <tfoot id='rDddk'></tfoot>
    1. <i id='rDddk'><tr id='rDddk'><dt id='rDddk'><q id='rDddk'><span id='rDddk'><b id='rDddk'><form id='rDddk'><ins id='rDddk'></ins><ul id='rDddk'></ul><sub id='rDddk'></sub></form><legend id='rDddk'></legend><bdo id='rDddk'><pre id='rDddk'><center id='rDddk'></center></pre></bdo></b><th id='rDddk'></th></span></q></dt></tr></i><div id='rDddk'><tfoot id='rDddk'></tfoot><dl id='rDddk'><fieldset id='rDddk'></fieldset></dl></div>
    2. 如何修复:“找不到适合 jdbc:mysql://localhost/dbname

      时间:2023-08-17
        <tfoot id='EGsnT'></tfoot>
        • <i id='EGsnT'><tr id='EGsnT'><dt id='EGsnT'><q id='EGsnT'><span id='EGsnT'><b id='EGsnT'><form id='EGsnT'><ins id='EGsnT'></ins><ul id='EGsnT'></ul><sub id='EGsnT'></sub></form><legend id='EGsnT'></legend><bdo id='EGsnT'><pre id='EGsnT'><center id='EGsnT'></center></pre></bdo></b><th id='EGsnT'></th></span></q></dt></tr></i><div id='EGsnT'><tfoot id='EGsnT'></tfoot><dl id='EGsnT'><fieldset id='EGsnT'></fieldset></dl></div>

            <legend id='EGsnT'><style id='EGsnT'><dir id='EGsnT'><q id='EGsnT'></q></dir></style></legend>

              <tbody id='EGsnT'></tbody>

            <small id='EGsnT'></small><noframes id='EGsnT'>

              • <bdo id='EGsnT'></bdo><ul id='EGsnT'></ul>

              • 本文介绍了如何修复:“找不到适合 jdbc:mysql://localhost/dbname 的驱动程序";使用池时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试创建到我的数据库的连接,当我使用 main 方法测试我的代码时,它可以无缝地工作.但是,当尝试通过 Tomcat 7 访问它时,它失败并显示错误:

                I am trying to create a connection to my database, when I put test my code using the main method, it works seamlessly. However, when trying to access it through Tomcat 7, it fails with error:

                No suitable driver found for jdbc:mysql://localhost/dbname. 
                

                我正在使用池化.我在 WEB-INF/lib 和 .classpath 中放入了 mysql 连接器 (5.1.15)、dbcp (1.4) 和 pool(1.4.5) 库.我正在使用 Eclipse IDE.我的数据库驱动程序代码是:

                I am using pooling. I put in mysql connector (5.1.15), dbcp (1.4) , and pool(1.4.5) libraries in WEB-INF/lib and in .classpath as well. I am using Eclipse IDE. My code for the database driver is:

                import java.sql.Connection;
                import java.sql.DriverManager;
                import java.sql.SQLException;
                
                import org.apache.tomcat.dbcp.dbcp.ConnectionFactory;
                import org.apache.tomcat.dbcp.dbcp.DriverManagerConnectionFactory;
                import org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory;
                import org.apache.tomcat.dbcp.dbcp.PoolingDriver;
                import org.apache.tomcat.dbcp.pool.impl.GenericObjectPool;
                
                public class DatabaseConnector {
                    public static String DB_URI = "jdbc:mysql://localhost/dbname";
                    public static String DB_USER = "test";
                    public static String DB_PASS = "password";
                
                    // Singleton instance
                    protected static DatabaseConnector _instance;
                
                    protected String _uri;
                    protected String _username;
                    protected String _password;
                
                    /**
                     * Singleton, so no public constructor
                     */
                    protected DatabaseConnector(String uri, String username, String password) {
                        _uri = uri;
                        _username = username;
                        _password = password;
                
                        GenericObjectPool connectionPool = new GenericObjectPool(null);
                        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                            _uri, _username, _password);
                        PoolableConnectionFactory poolableConnectionFactory =
                            new PoolableConnectionFactory(connectionFactory, connectionPool,
                                                            null, null, false, true);
                        PoolingDriver driver = new PoolingDriver();
                        driver.registerPool("test", connectionPool);
                    }
                
                    /**
                     * Returns the singleton instance
                     */
                    public static DatabaseConnector getInstance() {
                        if (_instance == null) {
                            _instance = new DatabaseConnector(DB_URI, DB_USER, DB_PASS);
                        }
                        return _instance;
                    }
                
                    /**
                     * Returns a connection to the database
                     */
                    public Connection getConnection() {
                        Connection con = null;
                        try {
                            con = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
                        } catch (SQLException e) {
                            throw new RuntimeException(e);
                        }
                        return con;
                    }
                }
                

                我的堆栈跟踪的开始:

                Apr 5, 2011 9:49:14 PM org.apache.catalina.core.StandardWrapperValve invoke
                SEVERE: Servlet.service() for servlet [Login] in context with path [/Project] 
                threw exception
                java.lang.RuntimeException: java.sql.SQLException: 
                No suitable driver found for jdbc:mysql://localhost/dbname
                

                是什么导致了这个错误?

                What is causing this error?

                推荐答案

                尝试将驱动程序 jar 放在服务器 lib 文件夹中.($CATALINA_HOME/lib)

                Try putting the driver jar in the server lib folder. ($CATALINA_HOME/lib)

                我相信甚至在应用程序实例化之前就需要设置连接池.(至少在 Jboss 中是这样的)

                I believe that the connection pool needs to be set up even before the application is instantiated. (At least that's how it works in Jboss)

                这篇关于如何修复:“找不到适合 jdbc:mysql://localhost/dbname 的驱动程序";使用池时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在 MySQL 的 CONCAT 中使用 GROUP_CONCAT 下一篇:MySQL查询/子句执行顺序

                相关文章

                最新文章

                <tfoot id='UnKIR'></tfoot>
                • <bdo id='UnKIR'></bdo><ul id='UnKIR'></ul>
              • <i id='UnKIR'><tr id='UnKIR'><dt id='UnKIR'><q id='UnKIR'><span id='UnKIR'><b id='UnKIR'><form id='UnKIR'><ins id='UnKIR'></ins><ul id='UnKIR'></ul><sub id='UnKIR'></sub></form><legend id='UnKIR'></legend><bdo id='UnKIR'><pre id='UnKIR'><center id='UnKIR'></center></pre></bdo></b><th id='UnKIR'></th></span></q></dt></tr></i><div id='UnKIR'><tfoot id='UnKIR'></tfoot><dl id='UnKIR'><fieldset id='UnKIR'></fieldset></dl></div>

                    <small id='UnKIR'></small><noframes id='UnKIR'>

                  1. <legend id='UnKIR'><style id='UnKIR'><dir id='UnKIR'><q id='UnKIR'></q></dir></style></legend>