Use JSP to connect MySQL database to read HTML form data for storage

Source: Internet
Author: User

Operating Environment tomcat5.5+mysql5.0
Write a simple HTML form:
<body>
<form action= "http://127.0.0.1/test/login.jsp" method= "POST" >
School Number: <input type= "text" name= "id" ><br>
Name: <input type= "text" name= "name" ><br>
<label>
<input type= "Radio" name= "Sex" value= "boy" checked>
Male </label>
<label>
<input type= "Radio" name= "Sex" value= "Girl" >
Women </label><br>
Tel: <input type= "Text" name= "Tel" ><br>
<input type= "Submit" value= "Submission" >
<input type= "reset" value= "refill" >
</form>
</body>
Connection conn = null;
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
conn = Java.sql.DriverManager.getConnection ("Jdbc:mysql://localhost/mydb", "Root", "Corsair");
if (conn==null){
System.out.println ("Get conn error");
}
Statement stmt=conn.createstatement ();
resultset rs=null;
%>
<%
    string id,name,sex,tel;
    id=request.getparameter ("id");
    name=request.getparameter ("name");
    sex=request.getparameter ("sex");
    tel=request.getparameter ("tel");
    try{
     Stmt.executeupdate ("Insert into inf_student (Id,name,sex,tel)  VALUES  ('" +id+ "', '" +name+ "', ' "+sex+" ', ' "+tel+" ') ");
    }catch (sqlexception e) {}
Stmt.close ();
Conn.close ();
%> Save the above file in the WebApps directory of the tomcat5.5, then start the tomcat5.5 and MySQL database, open the form, insert the data submission, and mysqlquerybrower to see the data inserted.

Posted on 2006-09-15 15:42 Galaxy Pirate Reading (1170) Comment (4) Edit favorite Category: WEB

Use JSP to connect MySQL database to read HTML form data for storage

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.