乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      JSP連接SQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)查找/插入信息

       Ethan的博客 2010-12-29

      JSP連接SQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)查找/插入信息[參考] 收藏

       
       
      JSP連接SQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)查找(支持模糊查找,查找年齡段),插入信息<實(shí)例>
      本代碼適合JSP初學(xué)者!轉(zhuǎn)載請(qǐng)注明出處謝謝!

      ====Search.html============================================================

      <html>
          <head>
              <title>學(xué)生信息查詢</title>
              <META http-equiv="Content-Type" content="text/html; charset=GB2312">
      </head>
      <!--Vmer設(shè)計(jì),QQ:6466909.轉(zhuǎn)載請(qǐng)注明出處.-->
      <body>
          <center>
          <h2>學(xué)生信息查詢</h2>
          <br />
          <br />
              <form method="POST" action="Name.jsp">
              <h4>按姓名查找(支持模糊查詢)</h4>
                  <table bgcolor="#CCCCCC">
                      <tr>
                          <td>查找姓名</td>
                          <td><input type="text" name="name" size="15" /></td>
                          <td><input type="submit" value="查找"></td>
                      </tr>
                  </table>
              </form>
              <br/>
              <br />
              <form method="POST" action="Age.jsp">
              <h4>按年齡查找</h4>
                  <table border="1" bgcolor="#CCCCCC">
                      <tr>
                          <td>查找年齡</td>
                          <td><input type="text" name="agemin" size="5" /></td>
                          <td>到</td>
                          <td><input type="text" name="agemax" size="5" /></td>
                          <td><input type="submit" value="查找"></td>
                      </tr>
                  </table>
              </form>
              <br />
              <br />
              <form action="Insert.jsp" method="POST">
              <h4>插入信息到表中</h4>
                  <table border="1" bgcolor="#cccccc">
                      <tr>
                          <td>姓名</td>
                          <td><input type="text" name="name" /></td>
                      </tr>
                      <tr>
                          <td>性別</td>
                          <td><input type="text" name="sex" /></td>
                      </tr>
                      <tr>
                          <td>年齡</td>
                          <td><input type="text" name="age" /></td>
                      </tr>
                      <tr>
                          <td>系別</td>
                          <td><input type="text" name="dept" /></td>
                      </tr>
                      <tr>
                          <td><input type="submit" value="插入" /></td>
                          <td><input type="reset" value="重置" /></td>
                      </tr>
                  </table>
              </form>
          </center>
      </body>
      </html>

      ========================================================================

      ====Name.jsp============================================================
      <%@ page contentType="text/html; charset=GBK" %>
      <%@ page import="java.sql.*" %>
      <html>
          <head>
              <title></title>
              <META http-equiv="Content-Type" content="text/html; charset=GBK">
          </head>
      <body>
          <%
          String name=request.getParameter("name");
          if(name==null)
          {
              name="";
          }
          byte b[]=name.getBytes("ISO-8859-1");
          name=new String(b);
          Connection con;
          Statement sql;
          ResultSet rs;

          try
          {//建立JDBC-ODBC橋驅(qū)動(dòng)程序,用到j(luò)ava.lang包中的類Class,調(diào)用其方法forName().
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
          catch(ClassNotFoundException e){}

          try
          {//創(chuàng)建連接對(duì)象con,它屬于Connection類,然后用類DriverManager調(diào)用getConnection().
              con=DriverManager.getConnection("jdbc:odbc:stu");
              sql=con.createStatement();//創(chuàng)建SQL語(yǔ)句對(duì)象.
              rs=sql.executeQuery("SELECT* FROM stuInfo WHERE stuName LIKE '%"+name+"%'");//執(zhí)行SQL語(yǔ)句并返回結(jié)果.
          %>
          <center>
              <h2>按姓名查找的學(xué)生信息</h2>
              <br />
              <br />
              <h4>輸出姓名為<%=name%>的學(xué)生信息:</h4>
              <table border="1" bgcolor="#cccccc"><!--設(shè)置用以表格顯示.-->
                  <tr>
                      <th width="50">學(xué)號(hào)</th>
                      <th width="50">姓名</th>
                      <th width="50">性別</th>
                      <th width="50">年齡</th>
                      <th width="50">系別</th>
                  </tr>
                  <%
                  while(rs.next())//順序取出結(jié)果集中的數(shù)據(jù).
                  {%>
                  <tr>
                      <td><%=rs.getString(1)%></td> <!---取出表中第一個(gè)字段-->
                      <td><%=rs.getString(2)%></td>
                      <td><%=rs.getString(3)%></td>
                      <td><%=rs.getInt(4)%></td>
                      <td><%=rs.getString(5)%></td>
                  </tr>
                  <%}%>
              </table>
          </center>
          <%
          con.close();
          }
          catch(SQLException e1){}
          %>
      </body>
      </html>

      ============================================================================

      =====Age.jsp================================================================
      <%@ page contentType="text/html; charset=GBK" %>
      <%@ page import="java.sql.*" %>
      <html>
          <head>
              <title>按姓名查找的學(xué)生信息</title>
          </head>
      <body>
          <%
          String agemin=request.getParameter("agemin");
          if(agemin==null)
          {
              agemin="0";
          }
          String agemax=request.getParameter("agemax");
          if(agemax==null)
          {
              agemax="100";
          }
          Connection con;
          Statement sql;
          ResultSet rs;

          try
          {//建立JDBC-ODBC橋驅(qū)動(dòng)程序,用到j(luò)ava.lang包中的類Class,調(diào)用其方法forName().
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
          catch(ClassNotFoundException e){}

          try
          {//創(chuàng)建連接對(duì)象con,它屬于Connection類,然后用類DriverManager調(diào)用getConnection().
              con=DriverManager.getConnection("jdbc:odbc:stu");
              sql=con.createStatement();//創(chuàng)建SQL語(yǔ)句對(duì)象.
              rs=sql.executeQuery("SELECT* FROM stuInfo WHERE stuAge<="+agemax+" AND stuAge>="+agemin+"");;//執(zhí)行SQL語(yǔ)句并返回結(jié)果.
          %>
          <center>
              <h2>按年齡查找的學(xué)生信息</h2>
              <br />
              <br />
              <h4>輸出年齡在<%=agemin%>與<%=agemax%>之間的學(xué)生信息:</h4>
              <table border="1" bgcolor="#cccccc"><!--設(shè)置用以表格顯示.-->
                  <tr>
                      <th width="50">學(xué)號(hào)</th>
                      <th width="50">姓名</th>
                      <th width="50">性別</th>
                      <th width="50">年齡</th>
                      <th width="50">系別</th>
                  </tr>
                  <%
                  while(rs.next())//順序取出結(jié)果集中的數(shù)據(jù).
                  {%>
                  <tr>
                      <td><%=rs.getString(1)%></td> <!---取出表中第一個(gè)字段-->
                      <td><%=rs.getString(2)%></td>
                      <td><%=rs.getString(3)%></td>
                      <td><%=rs.getInt(4)%></td>
                      <td><%=rs.getString(5)%></td>
                  </tr>
                  <%}%>
              </table>
          </center>
          <%
          con.close();
          }
          catch(SQLException e1){}
          %>
      </body>
      </html>

      ============================================================================

      ======Insert.jsp======================================================================

      <%@ page contentType="text/html; charset=GB2312" %>
      <%@ page import="java.sql.*" %>
      <html>
          <head>
              <title></title>
              <META http-equiv="Content-Type" content="text/html; charset=GB2312">
          </head>
          <body>
              <%
              String name=request.getParameter("name");
              if(name==null)
              {
                  name="";
              }
              byte b[]=name.getBytes("ISO-8859-1");
              name=new String(b);
              String sex=request.getParameter("sex");
              if(sex==null)
              {
                  sex="";
              }
              byte s[]=sex.getBytes("ISO-8859-1");
              sex=new String(s);
              String age=request.getParameter("age");
              String dept=request.getParameter("dept");
              if(dept==null)
              {
                  dept="";
              }
              byte d[]=dept.getBytes("ISO-8859-1");
              dept=new String(d);

              Connection con;
              Statement sql;
              ResultSet rs;
              Statement stmt;

              try
              {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }
              catch(ClassNotFoundException e){}

              try
              {
                  con=DriverManager.getConnection("jdbc:odbc:stu");
                  sql=con.createStatement();//創(chuàng)建SQL語(yǔ)句對(duì)象.
                  stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                  stmt.executeUpdate("INSERT INTO stuInfo VALUES ('"+name+"','"+sex+"','"+age+"','"+dept+"')");
                  rs=sql.executeQuery("SELECT* FROM stuInfo");
                  %>
                  <center>
                      <h2>學(xué)生信息表</h2>
                      <br />
                      <br />
                      <h4>輸出插入后的學(xué)生信息:</h4>
                      <table border="1" bgcolor="#cccccc"><!--設(shè)置用以表格顯示.-->
                          <tr>
                              <th width="50">學(xué)號(hào)</th>
                              <th width="50">姓名</th>
                              <th width="50">性別</th>
                              <th width="50">年齡</th>
                              <th width="50">系別</th>
                          </tr>
                          <%
                          while(rs.next())//順序取出結(jié)果集中的數(shù)據(jù).
                          {%>
                          <tr>
                              <td><%=rs.getString(1)%></td> <!---取出表中第一個(gè)字段-->
                              <td><%=rs.getString(2)%></td>
                              <td><%=rs.getString(3)%></td>
                              <td><%=rs.getInt(4)%></td>
                              <td><%=rs.getString(5)%></td>
                          </tr>
                          <%}%>
                      </table>
                  </center>
                  <%
                  con.close();
              }
              catch(SQLException e1)
              {
                  System.out.println(e1);
              }
              %>
          </body>
      </html>

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多