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

    <%@ 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_delete = "delete from employee where id='2'";
        int result_delete = stmt.executeUpdate(sql_delete);
       } catch (SQLException e) {
        out.println("delete失败!");
       }
       try {
        if (pstmt != null) {
         pstmt.close();
         pstmt = null;
        }
        if (conn != null) {
         conn.close();
         conn = null;
        }
       } catch (Exception e) {
        out.println("数据库关闭异常!");
       }
       out.println("delete成功!");
      %>
     </center>
    </body>
    </html>

  • 相关阅读:
    python闭包&深浅拷贝&垃圾回收&with语句
    Python基本数据类型
    面向对象
    四则运算2
    周总结01
    软件工程个人作业01
    java web中乱码的种类和一些解决方式
    java web 增加信息课堂测试00
    课程00作业
    动手动脑07
  • 原文地址:https://www.cnblogs.com/atwanli/p/2772226.html
Copyright © 2011-2022 走看看