<data-sources>
<!-- 设置数据源标识 -->
<data-source key="sqlDB1" type="org.apache.commons.dbcp.BasicDataSource">
<!-- 设置数据库驱动对应类名 -->
<set-property property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<!-- 设置待连接数据源URL -->
<set-property property="url" value="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=dbname" />
<!-- 设置同时打开连接的最大数目 -->
<set-property property="maxActive" value="5"/>
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="true" />
<set-property property="defaultReadOnly" value="false" />
<set-property property="username" value="sa"/>
<set-property property="password" value="sa"/>
</data-source>
</data-sources>
data Source 里的 key 是区分 数据源的(需要导包)
--------------------------Action中每个----------------------
DataSource ds=this.getSource(request);
model.insert(Userform f,DataSource ds);
------------------------传送到 bean---------------
public void insert (Userform f,DataSource ds)
bean接受 用 ds.getconection().preparestatement(sql);
------------------------------设置PlugIn------------------------------↑免-------
------------------------DbConn类----------------------------
public class DbConn implements PlugIn{
Connection con;
DataSource ds=null;
public Connection SetCon(){
try {
con=ds.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public void destroy() {
// TODO Auto-generated method stub
}
public void init(ActionServlet servlet, ModuleConfig config)
throws ServletException {
ds=(DataSource) servlet.getServletConfig().getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
}
}
-------------------------------------------Struts-config.xml--------------------------
<message-resources parameter="com.struts.ApplicationResources" />
<plug-in className="com.common.DbConn" id="DbConn">
</plug-in>
---------------------配置完plugIn-------------------------------------------------