参考:
http://blog.csdn.net/gotoidea/archive/2004/07/29/55048.aspx
三个需要的程序包:
commons-dbcp-1.2.1.jar
http://apache.linuxforum.net/dist/jakarta/commons/dbcp/binaries/
struts-legacy.jar
http://apache.linuxforum.net/dist/jakarta/struts/struts-legacy/
commons-pool-1.2.jar
http://apache.linuxforum.net/dist/jakarta/commons/pool/binaries/
struts-config.xml:
<data-sources >
<data-source id="DS" key="myPool" type="org.apache.commons.dbcp.BasicDataSource" >
<set-property value="jdbc:mysql://localhost/mytest" property="url" />
<set-property value="bitan" property="username" />
<set-property value="bb" property="password" />
<set-property value="org.gjt.mm.mysql.Driver" property="driverClassName" />
<set-property value="true" property="autoCommit" />
</data-source>
</data-sources>
DataSourceAction.java:
……
DataSourceForm myform = (DataSourceForm) form;
DataSource ds = getDataSource(request, "myPool");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
String sql = "SELECT * FROM struts";
ResultSet rs = stmt.executeQuery(sql);
……