자바 사용 mysql-connector-java 조작 데이터베이스:업데이트,삭제,삽입

1067 단어 프로그램 개발
    //  、  、  
    public static void update() throws ClassNotFoundException, SQLException {
        String sql = "update sql.t_backend_user_role set create_time='2017-05-22 23:29:27' where id=277";//    
//        String sql = "delete from sql.t_backend_user_role where id=281 or id=279";//    
//        String sql = "insert into sql.t_backend_user_role(id,role_id,backend_user_id,create_time) values(279,8,9,'2020-08-08 00:00:00')";//    
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.10.102/?useUnicode=true&characterEncoding=UTF-8", "", "");
        Statement stmt = conn.createStatement();
        int count = stmt.executeUpdate(sql);
        if (count == 0) {
            System.out.println("      :" + sql);
        } else {
            System.out.println("  " + count + "     :" + sql);
        }
        stmt.close();
        conn.close();
    }

좋은 웹페이지 즐겨찾기