请教 struts中microsoft sql server的配置
问题如题! 搜索更多相关主题的帖子:
struts sql server microsoft
----------------解决方案--------------------------------------------------------
struts-config.xml中配置
<data-sources>
<data-source key="org.apache.struts.action.DATA_SOURCE" type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<set-property property="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs" />
<set-property property="username" value="sa" />
<set-property property="password" value="" />
<set-property property="maxActive" value="10" />
<set-property property="maxIdle" value="3" />
<set-property property="maxWait" value="60000" />
<set-property property="defaultAutoCommit" value="true" />
<set-property property="defaultReadOnly" value="false" />
</data-source>
</data-sources>
Action中调用
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
DataSource ds = this.getDataSource(request);
Connection con = ds.getConnection();
System.out.println(con);
return null;
}
需要导的包:javax.sql.DataSource,java.sql.Connection
需要添加的外部开源包commons-pool-1.3.jar,commons-dbcp-1.2.1.jar(这两个包到网上去下多的很)
----------------解决方案--------------------------------------------------------