Jsp--tomcat-mysql Web page Query

Source: Internet
Author: User

The querystudent.jsp code is as follows

<%@ page language="Java"Contenttype="text/html; charset=gb2312"pageencoding="UTF-8"%><! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">"border-right: #89d4f8 1px solid;border-Top: #89d4f8 1px solid; Border-left: #89d4f8 1px solid"cellspacing=0cellpadding= -Align=center bgcolor= #ffffff border=0> <tbody> <tr> <td height= ->&nbsp;&nbsp; Add student information </td> </tr> <tr> <td height=1bgcolor= #89d4f8 > </td> </tr> </tbody> </table> <!--click button Search <form name=messages method="Post"action="after_querystudent.jsp"> <table width=" -"align="Center"Border="0"> <tr> <td width=" the"></td> <td><input type="Submit"Value="Find all student information"></td> </tr> </table> </form></body>

After_querystudent.jsp page Code

<%@ page language= "Java"Import= "Java.util.*"Import= "Com.mysql.jdbc.Driver"Import= "Java.sql.*"ContentType= "text/html;charset=gb2312"pageencoding= "UTF-8"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >Connection Conn;   Statement Stat; //set the URL of the connection, where student is the database nameString url= "Jdbc:mysql://localhost:3306/student"; //I am using the free install version of MySQL, User: root, Password: ZhangweijieString username= "Root"; String Password= "Zhangweijie"; Try{          //registering the JDBC driverClass.forName ("Com.mysql.jdbc.Driver"); }       Catch(ClassNotFoundException ex) {out.println ("Driver not Found!" "); }       //Open a database connectionconn=drivermanager.getconnection (Url,username,password); Try{stat=conn.createstatement (); //If there is a data table with the same name, delete it firstResultSet result=stat.executequery ("select * from Student_info;"); //Draw a table to display the dataOut.println ("<table border>"); Out.println ("&LT;TR&GT;&LT;TD colspan=3 align=center> Student Information </td></tr>"); Out.println ("<tr>"); Out.println ("<td width=150> </td>"); Out.println ("&LT;TD width=150> name </td>"); Out.println ("&LT;TD width=150> Contact Phone </td>"); Out.println ("</tr>");  while(Result.next ()) {//reads the query results and displaysOut.println ("<tr>"); Out.println ("<td>" +result.getint (1) + "</td>"); Out.println ("<td>" +result.getstring (2) + "</td>"); Out.println ("<td>" +result.getstring (3) + "</td>"); Out.println ("</tr>"); }                              }        Catch(SQLException ex) {out.println ("Data table operation failed!"); }        finally{conn.close (); } %></body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.