随笔 - 64  文章 - 9  trackbacks - 0
<2021年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

常用链接

留言簿(6)

我参与的团队

随笔分类(88)

随笔档案(92)

文章分类(142)

文章档案(182)

天基成员

学习园

我的海角

搜索

  •  

积分与排名

  • 积分 - 162731
  • 排名 - 337

最新评论

mysql语句
create database oa;
use oa;
create table employee(
id int primary key auto_increment,
name varchar(60),
address varchar(60),
sex varchar(2),
age int
);

往mysql中插入数据
insert into employee(name,address,sex,age)values('王强','南阳','男','18');
insert into employee(name,address,sex,age)values('张帅','周口','男','20');
insert into employee(name,address,sex,age)values('赵丽','信阳','女','19');
insert into employee(name,address,sex,age)values('李梅','新乡','女','22');
insert into employee(name,address,sex,age)values('杨广','郑州','男','21');
insert into employee(name,address,sex,age)values('柳烟','洛阳','女','20');



find.jsp
<%@ page contentType="text/html;charset=gbk" import="java.sql.*"%>
<html>
<body>
<center>
<Br>
<form action="" method="post" name="form1">
<table  width="500">
<tr>
<td>选择查询条件:</td>
<td><select name="tiaojian" width=80>
    <option value="name">姓  名</option>
<option value="sex">性  别</option>
<option value="age">年  龄</option>
<option value="address">地址</option>
</selct></td>
<td><input type="text" name="result"></td>
<td> <input type="submit" value="  提    交  "></td>
</tr>
</table>
</form>
<table border=1 width="800">
<tr>
<td>姓名</td><td>年龄</td><td>性别</td><td>地址</td>
</tr>
<%
Connection con = null;
Statement stmt= null;
ResultSet rs = null;
String sql ="";
sql="select * from employee";

String tiaojian = request.getParameter("tiaojian");
String result = request.getParameter("result");
if(tiaojian!=null&&result!=null){
result = new String(result.getBytes("iso-8859-1"),"gbk");
  sql ="select * from employee where "+tiaojian+"='"+
       result+"'";
}
//out.print(sql);换数据库仅class--rs不同
try{
  Class.forName("com.mysql.jdbc.Driver");
  con = DriverManager.getConnection(
  "jdbc:mysql://localhost:3306/oa","root","yu");
  stmt = con.createStatement();
  rs = stmt.executeQuery(sql);
 while(rs.next()){
%>
<tr>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("age")%></td>
<td><%=rs.getString("sex")%></td>
<td><%=rs.getString("address")%></td>
</tr>

<%
 }
 con.close();//要关数据库,否则会使数据库崩溃
 }catch(Exception e){e.printStackTrace();}
%>

</table>
</center>
</body>
</html>

posted on 2009-04-13 11:52 鹏凌 阅读(40) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: