<%@ page language= "java" import= "java.sql.*" pageencoding= "UTF-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Add a record page with PreparedStatement object </title>
<body>
<%
String drivername= "Com.mysql.jdbc.Driver";
String username= "root";
String userpwd= "147258369";
String dbname= "Student";
String url1= "jdbc:mysql://localhost:3306/" +dbname;
String url2= "? user=" +username+ "&password=" +USERPWD;
String url3= "&useunicode=true&characterencoding=utf-8";
String Url=url1+url2+url3;
Class.forName (drivername);
Connection conn=drivermanager.getconnection (URL);
String sql= "Insert into Meng (id,name,sex,age,weight,hight) value (?,?,?,?,?,?)";
PreparedStatement pstmt=conn.preparestatement (SQL);
Request.setcharacterencoding ("UTF-8");
int Id=integer.parseint (Request.getparameter ("id"));
String name=request.getparameter ("name");
String sex=request.getparameter ("sex");
int Age=integer.parseint (Request.getparameter ("Age"));
Float Weight=float.parsefloat (Request.getparameter ("weight"));
Float Hight=float.parsefloat (Request.getparameter ("hight"));
Pstmt.setint (1,id);
Pstmt.setstring (2,name);
Pstmt.setstring (3,sex);
Pstmt.setint (4,age);
Pstmt.setfloat (5,weight);
Pstmt.setfloat (6,hight);
int n=pstmt.executeupdate ();
if (n==1) {%> data insert operation succeeded! <br> <%}
Else{%> Data insert operation failed! <br> <%}
if (pstmt!=null) {pstmt.close ();}
if (conn!=null) {conn.close ();} %>
</body>
Java Web insert_stu_1.jsp page 95th