zoukankan      html  css  js  c++  java
  • 必须使用Statement案例

    package com.bjpowernode.jdbc;
    
    import java.sql.*;
    
    /**
     * @Author:杨青
     * @Time:2021/10/26 17:09
     * @Description:
     *      PreparedStatement完成insert delete update
     */
    public class JDBCTest09 {
        public static void main(String[] args) {
            Connection conn=null;
            PreparedStatement ps=null;
            try {
                //1.类加载完成注册驱动
                Class.forName("com.mysql.jdbc.Driver");
                //2.获取连接
                conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/bjpowernode","root","123456");
                //3.获取预编译数据库操作对象
                //String sql="insert into t_user (loginName,loginPwd,realName)values(?,?,?)";
                //String sql="update t_user set loginName='python',loginPwd='111',realName='Python' where id=4";
                String sql="delete from t_user where id=4 ";
                ps=conn.prepareStatement(sql);
                /*
                ps.setString(1,"java");
                ps.setString(2,"000");
                ps.setString(3,"Java");
                //4.执行sql语句
                 */
                int count=ps.executeUpdate();
                System.out.println("执行语句条数:"+count);
            } catch (Exception e) {
                e.printStackTrace();
            }  finally {
                //6.释放资源
                if(ps!=null){
                    try {
                        ps.close();
                    } catch (SQLException throwables) {
                        throwables.printStackTrace();
                    }
                }
                if(conn!=null){
                    try {
                        conn.close();
                    } catch (SQLException throwables) {
                        throwables.printStackTrace();
                    }
                }
            }
        }
    }
    

      

  • 相关阅读:
    (转)了解JNDI
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver问题
    占个座
    关于 inode 与 iblock 的知识
    机器学习性能度量指标:ROC曲线、查准率、查全率、F1
    编译出现的问题解决
    二分查找(Binary Search)
    ST算法 Sliding Window algorithm template
    数据结构_算法
    知识点积累
  • 原文地址:https://www.cnblogs.com/-slz-2/p/15467652.html
Copyright © 2011-2022 走看看