ITEEDU 与Tomcat一起使用Connector/J


首先安装与Connector/J in $CATALINA_HOME/common/lib一起提供的.jar文件,以便它能用于已安装的所有应用程序。

其次,在定义Web应用程序的Context(场景)内,通过为$CATALINA_HOME/conf/server.xml增加声明资源,配置JNDI DataSource:

<Context ....>


  <Resource name="jdbc/MySQLDB"

  <!-- The name you used above, must match _exactly_ here!

       The connection pool will be bound into JNDI with the name

  <ResourceParams name="jdbc/MySQLDB">

    <!-- Don't set this any higher than max_connections on your
         MySQL server, usually this should be a 10 or a few 10's
         of connections, not hundreds or thousands -->


    <!-- You don't want to many idle connections hanging around
         if you can avoid it, only enough to soak up a spike in
         the load -->


    <!-- Don't use autoReconnect=true, it's going away eventually
         and it's a crutch for older connection pools that couldn't
         test connections. You need to decide if your application is
         supposed to deal with SQLExceptions (hint, it should), and
         how much of a performance penalty you're willing to pay
         to ensure 'freshness' of the connection -->

      <value>SELECT 1</value>

   <!-- The most conservative approach is to test connections
        before they're given to your application. For most applications
        this is okay, the query used above is very small and takes
        no real server resources to process, other than the time used
        to traverse the network.

        If you have a high-load application you'll need to rely on
        something else. -->


   <!-- Otherwise, or in addition to testOnBorrow, you can test
        while connections are sitting idle -->


    <!-- You have to set this value, otherwise even though
         you've asked connections to be tested while idle,
         the idle evicter thread will never run -->


    <!-- Don't allow connections to hang out idle too long,
         never longer than what wait_timeout is set to on the
         server...A few minutes or even fraction of a minute
         is sometimes okay here, it depends on your application
         and how much spikey load it will see -->


    <!-- Username and password used when connecting to MySQL -->



    <!-- Class name for the Connector/J driver -->


    <!-- The JDBC connection url for connecting to MySQL, notice
         that if you want to pass any other MySQL-specific parameters
         you should pass them here in the URL, setting them using the
         parameter tags above will have no effect, you will also
         need to use &amp; to separate parameter values as the
         ampersand is a reserved character in XML -->




Error: java.sql.SQLException: Cannot load JDBC driver class 'null ' SQL
state: null