配置java+jsp+tomcat+mysql 连接池配置
环境:
linux AS4 U5
Tomcat5.5.28
mysql 5.1.X
配置步骤:
1. 将mysql-connector-java-5.1.10-bin.jar复制到$CATALINA_HOME/common/lib目录下,或者在CLASSPATH中指定其位置也可
2. 配置tomcat下的conf下的context.xml文件,在<context></context>之间添加连接池如下:
- <Resource name="jdbc/mysql"
- auth="Container"
- type="javax.sql.DataSource"
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://localhost/mysql"
- username="root"
- password="password"
- maxActive="100"
- maxIdle="30"
- maxWait="10000" />
- <!-- maxActive: Maximum number of dB 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 dB 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 dB 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 dB username and password for dB 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 dB.
- -->
3. 配置你的应用下的web.xml中的<web-app></web-app>之间加入(实际操作中,没做这步也通过了):
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/mysqlx</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
4. 测试代码:
- <!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd">
- <%@ page import="java.sql.*"%>
- <%@ page import="javax.sql.*"%>
- <%@ page import="javax.naming.*"%>
- <%@ page session="false" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title></title>
- <%
- out.print("我的测试开始");
- DataSource ds = null;
- try{
- InitialContext ctx=new InitialContext();
- ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
- Connection conn = ds.getConnection();
- Statement stmt = conn.createStatement();
- //提示:user必须是数据库已有的表,
- //这里的数据库前文提及的Data Source URL配置里包含的数据库。
- String strSql = "select * from user";
- ResultSet rs = stmt.executeQuery(strSql);
- while(rs.next()){
- out.print(rs.getString(1));
- }
- out.print("我的测试结束");
- }
- catch(Exception ex){
- out.print("Err:"+ex.getMessage());
- ex.printStackTrace();
- }
- %>
- </head>
- <body>
- </body>
- </html>
本日志由 flyinweb 于 2010-01-04 09:42:46 发表,目前已经被浏览 3818 次,评论 0 次;
作者添加了以下标签: mysql 连接池,MySQL Connector/J;
引用通告:http://www.517sou.net/Article/373/Trackback.ashx
It is quite useful and interesting too.
VIRT 的上限是64G,也就是36位, cat /proc/cpuinfo的结果是:addre
昨天要准备用线程重写webbench,试验了下Fedora Linux 2.6.35.14
不明白您的具体的意思是什么?
已经发送到你QQ邮箱
http://www.2mysite.net/scriptencoder/screnc.asp 站长你好,看
你好,我发现一个问题,就是从mysqld2同步过来的数据,在mysqld1的
晕,我说是怎么回事情,原来我和你一样,忘记设置了活动分区