<%@ page contentType="text/html;charset=gb2312"%>
<%@page language="java" import="java.sql.*" %>
<%@page language="java" import="java.util.*" %>
<html>
<head>
<title>数据库内容显示</title>
<script>
function chaxun(){
//document.getElementById("number").value;
document.f.submit();
}
</script>
<SCRIPT type="text/javascript">
function inform()
{
//a=document.getElementById("number").value;
var a=document.all.number.value;
if(a=="")alert("不能为空");
else
alert("输入值为"+a);
}
</SCRIPT>
</head>
<body>
<h1 align="center">数据库查询</h1>
<form action="" method="post" name="f" id="f">
<div align="center">
号码:<input type="text" id="number" name="number" >
<input type="submit" name="submit" value=" 查询 " οnclick="chaxun();"/>
<!-- <input type="button" name="test" value="显示输入值" οnclick="inform();"> -->
<br><br>
</div>
<hr/>
</form>
<%String number = request.getParameter("number"); //获取页面传来的号码
if(number==""){}
else{
//查询的语句
String sql = "SELECT * FROM [lhm].[dbo].[liaopin] where [号码]='" + number + "'";
//String sql = "SELECT * FROM [lhm].[dbo].[liaopin] ";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://10.144.79.43:1433";
String user="sa";
String password="";
Class.forName(driver).newInstance();
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery(sql); %>
<table align="center" border="1" cellpadding="10">
<% while(rs.next()) {%>
<tr><td> 号码 </td>
<td><% out.print(" "+rs.getString(1)+" ");%></td></tr>
<tr><td> 名称 </td>
<td><% out.print(" "+rs.getString(2)+" ");%></td></tr>
<tr><td> 描述 </td>
<td><% out.print(" "+rs.getString(3)+" ");%></td></tr>
<%}
rs.close();
stmt.close();
conn.close();}%>
</table>
</body>
</html>