`
jinxhj2003
  • 浏览: 145245 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
社区版块
存档分类
最新评论

struts数据源的配置

阅读更多
3个包:可以到apche去下载  commons-dpcp,commons-pool ,servlet-api.

在struts-config.xml中配置是:

<data-sources>
      <data-source key="org.apache.struts.action.DATA_SOURCE" type="org.apache.commons.dbcp.BasicDataSource">
            <set-property property="url" value="jdbc:mysql://127.0.0.1:3306/jxtv3" />
            <set-property property="username" value="root" />
            <set-property property="password" value="1234" />
            <set-property property="minCount" value="1" />
            <set-property property="maxCount" value="10" />
            <set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
        </data-source>

    </data-sources>

在struts中应用:

javax.sql.DataSource ds = null;
java.sql.Connection conn = null;
java.sql.Statement stmt = null;
ds = getDataSource(request);
conn = ds.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
java.sql.ResultSet rs = stmt
.executeQuery("SELECT * FROM zjy_tb ORDER BY id");

while (rs.next()) {

System.out.println(rs.getString(1));
}
//      return null;
request.getSession().setAttribute("conn",ds);
return mapping.findForward("ok");
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics