JDBC连sql server 2005

网上的帖子真是误人子弟,搜出来的全是垃圾,现总结一下正确的步骤:

1、下载sqljdbc_1.2.2828.100_chs

http://www.microsoft.com/downloads/details.aspx?familyid=C47053EB-3B64-4794-950D-81E1EC91C1BA&displaylang=zh-cn

2、将sqljdbc.jar放入D:\Tomcat\common\lib和D:\Tomcat\webapps\ora\WEB-INF\lib (ora是应用程序目录)

3、server.xml:

 

<Context path="/ora" docBase="ora" debug="5" reloadable="true" crossContext="true">

          <Resource name="jdbc/sqlserver" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000" username="wangxin" password="wangxin"
        driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
               url="jdbc:sqlserver://localhost:1433;DatabaseName=ora; "/>
        </Context>

......      </Host>

4、web.xml:

  <!-- Used by the JSTL database actions -->
  <context-param>
    <param-name>
     javax.servlet.jsp.jstl.sql.dataSource
    </param-name>
    <param-value>
 jdbc/sqlserver
 <!-- jdbc:mysql:///test,org.gjt.mm.mysql.Driver -->
    </param-value>
  </context-param>

5、搞定!

写段代码来测试一下:

 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>


<sql:query var="empDbInfo">
  SELECT * FROM Employee
    WHERE UserName = ?
  <sql:param value="${param.userName}" />
</sql:query>


 

 

你可能感兴趣的:(sql server 2005)