开发者

How to configure tomcat 6.0 for mysql

I'm using Tomcat 6.开发者_Python百科0, and I want to know how can I configure Tomcat's server.xml file to connect to mysql database, and enable form based authentication in java.

I'm currently using mysql 5.1, and I've already downloaded mysql connector jar file, and put in lib directory of Tomcat.


I'm guessing you want Tomcat to create connection pool to MySQL database. In that case, you don't need to configure server.xml file. In the context.xml file you need to add a <Resource> element, something like this:

<Resource name="jdbc/MySQLPool" auth="Container" type="javax.sql.DataSource"
          factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
          maxActive="100" maxIdle="30" maxWait="10000"
          username="USERNAME" password="PASSWORD"
          driverClassName="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
          url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=Cp1251"
          removeAbandoned="true" />

(I'm not sure if that's the correct driverClassName for MySQL, but your Resource should look somewhat like this).

For more info, try checking Tomcat's documentation on JNDI Resources and JDBC DataSources.


Typically context.xml and server.xml are separated, and you usually configure a data source on web-app level, that is in the context of that web app. The reason for that is that a data source connects not so much to a server but to a database within that server, and having multiple apps accessing the same database is not always a good idea (if you didn't design the apps for that).

That said, have a look at this tomcat wiki page which describes what you want (or what I think you want).

For authentication check out this thread on velocity reviews.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜