(1)下载对应数据库版本的jdbc驱动并安装,注意安装后的得到的三个文件msbase.jar,mssqlserver.jar,msutil.jar,将其拷贝到jsp项目的WEB-INF/lib下面,也拷贝到Tomcat安装目录的lib下面,没有具体测试,应该和配置文件有关系。
%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
html>
body>
%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="data","sa","123456");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
{
out.println("tr>");
out.println("td>"+rs.getInt("num")+"/td>");
out.println("td>"+rs.getString("name")+"/td>");
out.println("td>"+rs.getInt("age")+"/td>");
out.println("td>"+rs.getString("fromw")+"/td>");
out.println("td>"+rs.getString("school")+"/td>");
out.println("td>"+rs.getString("major")+"/td>");
out.println("td>"+rs.getInt("score")+"/td>");
out.println("/tr>");
out.println("/tr>");
}
rs.close();
stmt.close();
conn.close();
%>
/table>
/body>
/html>