Java Web insert_stu_1.jsp page 95th

Source: Internet
Author: User

<%@ 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

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.