zoukankan      html  css  js  c++  java
  • Java web insert_stu_1.jsp 第95页

    <%@ 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">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>利用preparedStatement对象添加一条记录页面</title>
    </head>
    <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){%> 数据插入操作成功!<br> <%}
    else{%> 数据插入操作失败! <br> <%}
    if(pstmt!=null){pstmt.close();}
    if(conn!=null){conn.close();}%>
    </body>
    </html>

  • 相关阅读:
    Kubernetes中部署MySQL
    内置函数-format()
    Jenkins-deploymnt
    一次遇到too many open files的解决详情
    一次nginx问题记录
    kickstart自动化安装系统
    Maven —— 命令行清除编译打包
    CURL 发送POST请求
    mysql的my.cnf配置参考
    利用nginx实现生产和灰度环境流量切换
  • 原文地址:https://www.cnblogs.com/meng2/p/7707236.html
Copyright © 2011-2022 走看看