当前位置: 代码迷 >> Java Web开发 >> 请教 struts中microsoft sql server的配置
  详细解决方案

请教 struts中microsoft sql server的配置

热度:187   发布时间:2008-03-22 19:18:18.0
请教 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(这两个包到网上去下多的很)
----------------解决方案--------------------------------------------------------
  相关解决方案