Skip to main content

Obtener los documentos de una base de datos en Couchdb

Mostrare un pequeño código en Java que utiliza Couchdb4j para interactuar con los documentos almacenados en Couchdb.


try {
            db = dbSession.getDatabase(dbname);
            if (db == null) {
                return false;
            }
            int count = db.getDocumentCount();
            if (count == 0) {
                NotifyDescriptor d = new NotifyDescriptor.Message("No existen documentos de la base de datos " + dbname, msgType);
                DialogDisplayer.getDefault().notify(d);
                return false;
            }
            ViewResults results = db.getAllDocuments();

            //definimos el los campos para mostrar en el jtable
             Object[] filas = new Object[4]; // Hay tres columnas en la tabla


            for (Document document : results.getResults()) {
                            String id = (String) document.get("id");
                             Document full = db.getDocument(document.getId());
                String lnombre =full.getString("archivo");
                String lfecha = full.getString("fecha");
                String lprefijo = full.getString("prefijo");
                String ltipo    = full.getString("tipo");
                
            }

            return true;
        } catch (Exception ex) {

            NotifyDescriptor d = new NotifyDescriptor.Message("ObtenerRegistros()  " + ex.getLocalizedMessage().toString(), msgTypeError);
            DialogDisplayer.getDefault().notify(d);
        }
        return false;
    }

Comments

Anonymous said…
Hello,

I have a inquiry for the webmaster/admin here at avbravo.blogspot.com.

Can I use some of the information from your blog post right above if I provide a backlink back to your site?

Thanks,
Peter
avbravo said…
The information is totally free you can use