JDBC—执行sql语句的通用方法

 1 /*
 2 
   * 执行 sql的方法集
 3      * delete,insert into ,update
 4      */
 5     public static void update(String sql){
 6         
 7             Connection connection=null;
 8             java.sql.Statement statement =null;
 9             try {
10                 //1.0获取数据库的连接
11                 connection=getConnection();
12                 //2.0调用Connection 对象的createStatement()方法
13                 statement=connection.createStatement();
14                 //3.0发送SQL语句:调用exexuteUpdate()方法
15                 statement.executeUpdate(sql);
16             } catch (Exception e) {
17                 e.printStackTrace();
18             }finally{
19              JDBCTools.release(statement, connection);
20             }
21         }

  


 

posted @ 2019-04-22 14:04  蔡蔡的弱鸡  阅读(1135)  评论(0)    收藏  举报