question: public boolean updateUserAcl ( String username , String dbgroupname , boolean visible ) { Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; try { conn = getConnection ( ) ; String sql = "select dbgroupname from " + USERACL_TABLENAME + " where username=? and dbgroupname=?" ; stmt = conn . prepareStatement ( sql ) ; stmt . setString ( 1 , username ) ; stmt . setString ( 2 , dbgroupname ) ; rs = stmt . executeQuery ( ) ; boolean findOne = false ; if ( rs != null && rs . next ( ) ) findOne = true ; DBUtils . close ( rs ) ; rs = null ; DBUtils . close ( stmt ) ; stmt = null ; if ( findOne ) { sql = "update " + USERACL_TABLENAME + " set visible=? where username=? and dbgroupname=?" ; stmt = conn . prepareStatement ( sql ) ; stmt . setInt ( 1 , visible ? 1 : 0 ) ; stmt . setString ( 2 , username ) ; stmt . setString ( 3 , dbgroupname ) ; stmt . execute ( ) ; DBUtils . close ( stmt ) ; stmt = null ; } else { sql = "insert into " + USERACL_TABLENAME + " (username, dbgroupname, visible) values (?, ?, ?)" ; stmt = conn . prepareStatement ( sql ) ; stmt . setString ( 1 , username ) ; stmt . setString ( 2 , dbgroupname ) ; stmt . setInt ( 3 , visible ? 1 : 0 ) ; stmt . execute ( ) ; } DBUtils . close ( stmt ) ; stmt = null ; conn . commit ( ) ; return true ; } catch ( Exception ex ) { logger . log ( Level . SEVERE , "Exception" , ex ) ; return false ; } finally { DBUtils . close ( rs ) ; DBUtils . close ( stmt ) ; DBUtils . close ( conn ) ; } }
target:  Update visibility of a single dbgroup for a user