Developer Factory

Tomcat 에 MySQL DBCP Example , UTF-8 사용하기 본문

Developer/DBMS

Tomcat 에 MySQL DBCP Example , UTF-8 사용하기

Jeremy.Park 2014. 7. 4. 10:56

Tomcat 에 MySQL DBCP Example

http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

Context configuration

Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context.

For example:

<Context>

    <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->

    <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->

    <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->

    <!-- username and password: MySQL username and password for database connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->

    <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest"/>

</Context>



Tomcat 에 UTF-8 사용하기


 URIEncoding=”UTF-8″ 설정을 입력하신 후 서버를 재시작 하시면 됩니다.


2
3
4
5
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" URIEncoding="UTF-8" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />