隨筆 - 64  文章 - 9  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(6)

          我參與的團隊

          隨筆分類(88)

          隨筆檔案(92)

          文章分類(142)

          文章檔案(182)

          天基成員

          學(xué)習(xí)園

          我的海角

          搜索

          •  

          積分與排名

          • 積分 - 184362
          • 排名 - 317

          最新評論

          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中插入數(shù)據(jù)
          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('李梅','新鄉(xiāng)','女','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);換數(shù)據(jù)庫僅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();//要關(guān)數(shù)據(jù)庫,否則會使數(shù)據(jù)庫崩潰
           }catch(Exception e){e.printStackTrace();}
          %>

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

          posted on 2009-04-13 11:52 鵬凌 閱讀(103) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 扶沟县| 黄石市| 镇赉县| 平顶山市| 荆门市| 龙游县| 彝良县| 柏乡县| 宁陵县| 盐池县| 金湖县| 南昌市| 南召县| 普宁市| 蒙自县| 洞口县| 长沙市| 闸北区| 屯留县| 容城县| 和政县| 大荔县| 从化市| 靖江市| 皮山县| 资兴市| 宜兰县| 鄢陵县| 抚宁县| 宁明县| 龙胜| 长宁区| 溆浦县| 嵊泗县| 洛南县| 无极县| 东乡县| 金溪县| 寿光市| 浦县| 远安县|