zoukankan      html  css  js  c++  java
  • jsp连接mysqlupdata操作

    <%@ page language="java" contentType="text/html; charset=gb2312"
     pageEncoding="gb2312" import="java.sql.*"%>
    <!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=gb2312">
    <title>update数据</title>
    </head>
    <body>
     <center>
       <%
        

    String url = "jdbc:mysql://localhost:3306/test";
       String user = "root";
       String password = "110";
       Connection conn = null;
       PreparedStatement pstmt = null;
       String driverName = "com.mysql.jdbc.Driver";
       try {

        Class.forName(driverName).newInstance();

        conn = DriverManager.getConnection(url, user, password);

       } catch (ClassNotFoundException e) {
        out.println(e);
       } catch (SQLException e) {
        out.println("连接SQLserver数据库失败!!!!!!");
       }

        
        try{
        Statement stmt = conn.createStatement();
        String sql_update = "update employee set age=58 where id='1'";
        int result_update = stmt.executeUpdate(sql_update);
        }catch(SQLException e){
         out.println("更新失败!");
        }
        try{
         if(pstmt!=null){
          pstmt.close();
          pstmt=null;
         }
         if(conn!=null){
          conn.close();
          conn=null;
         }
        }catch(Exception e){
         out.println("数据库关闭异常!");
        }
        out.println("更新成功!");
       %>
     </center>
    </body>
    </html>

  • 相关阅读:
    Linux/windows查看设置环境变量指令
    转载:windows查看进程相关指令
    Ubuntu开启SSHD服务
    Ubuntu root方式登录
    洛谷P1466 集合 Subset Sums
    洛谷P1726 上白泽慧音
    洛谷P1983 车站分级
    洛谷P2577 [ZJOI2005]午餐
    洛谷P1119 灾后重建
    P1169 [ZJOI2007]棋盘制作
  • 原文地址:https://www.cnblogs.com/atwanli/p/2772229.html
Copyright © 2011-2022 走看看