老样子:1.把msbase.jar,mssqlserver.jar,msutil.jar放入Tomcat 6.0\lib目录下,重启tomcat服务。
- <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
-
<%@ page import="java.sql.*" %>
-
<html>
-
<head>
-
<title>JSP查询数据操作示例</title>
-
</head>
-
<body>
-
<%
-
Connection conn = null;
-
Statement stat = null;
-
ResultSet rs = null;
-
//加载数据库驱动类
-
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
-
//数据库连接URL
-
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lab";
-
//数据库用户名
-
String user = "sa";
-
//数据库密码
-
String password = "sa";
-
//根据数据库参数取得一个数据库连接
-
conn = DriverManager.getConnection(url, user, password);
-
stat = conn.createStatement();
-
String sql = "select first from input_table";
-
rs = stat.executeQuery(sql);
-
%>
-
<table width="260" cellSpacing=0 height="12" style="font-size:10pt;border: 1pt">
-
<tr style="border:solid 1pt">
-
<td style="border:solid 1pt">内容</td>
-
</tr>
-
<%
-
while(rs.next())
-
{
-
out.print("
");
-
out.print("
"+rs.getString("first")+" | ");
-
out.print("
");
-
}
-
if(rs != null)
-
{
-
rs.close();
-
}
-
if(stat!=null)
-
{
-
stat.close();
-
}
-
if(conn!=null)
-
{
-
conn.close();
-
}
-
%>
-
</table>
-
</body>
-
</html>
添加一张运行效果:)
阅读(11652) | 评论(1) | 转发(0) |