CSDN博客

img chho

配置struts数据源

发表于2004/10/28 17:00:00  1297人阅读

三个需要的程序包:

commons-dbcp-1.2.1.jar
struts-legacy.jar
commons-pool-1.2.

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);

……

阅读全文
0 0

相关文章推荐

img
取 消
img