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