MySQL數據庫查詢鎖行代碼示例

JdbcFactory jdbc = new JdbcFactory();
        String sqld = "select id from hnebony_user where  username REGEXP '"
                + usernamebefor + "[1-9][0-9]+' and telephone='' LIMIT 0,1 for update";
        Connection conn = jdbc.conn;
        try {
            conn.setAutoCommit(false);
            Statement stat = conn.createStatement();
            ResultSet re = stat.executeQuery(sqld);
            int id = 0;
            while(re.next()){
                id = re.getInt(1);
                System.out.println(id);
            }
            String sql = "update hnebony_user set telephone='" + phone
                    + "',active_time='" + date + "',callingID='" + mac
                    + "',address='" + ip + "',IDcard='" + wxbz + "',name='"
                    + weizhiId + "',pause_time='" + datelift
                    + "',modified_by='" + shebei + "' where id=" + id;
            stat.execute(sql);
            conn.commit();
            re.close();
            stat.close();
            conn.close();
            return 1;
        } catch (SQLException e) {
            e.printStackTrace();
        }
發佈了15 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章