Example usage for java.sql ResultSet getClob

List of usage examples for java.sql ResultSet getClob

Introduction

In this page you can find the example usage for java.sql ResultSet getClob.

Prototype

Clob getClob(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a Clob object in the Java programming language.

Usage

From source file:com.wabacus.config.database.type.DB2.java

public String getClobValue(ResultSet rs, String column) throws SQLException {
    Clob clob = (Clob) rs.getClob(column);
    if (clob == null)
        return "";
    BufferedReader in = null;/*from   w w w  . j a  va2 s. c  o  m*/
    try {
        in = new BufferedReader(clob.getReader());
        StringBuffer sbuffer = new StringBuffer();
        String str = in.readLine();
        while (str != null) {
            sbuffer.append(str).append("\n");
            str = in.readLine();
        }
        return sbuffer.toString();
    } catch (Exception e) {
        log.error("?" + column + "", e);
        return null;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.esri.geoportal.harvester.beans.HistoryManagerBean.java

@Override
public History.Event read(UUID id) throws CrudlException {
    try (Connection connection = dataSource.getConnection();
            PreparedStatement st = connection
                    .prepareStatement("SELECT taskid,started,completed,report,id FROM EVENTS WHERE ID = ?");) {
        st.setString(1, id.toString());//from   w  ww .j a v  a  2  s.  com
        ResultSet rs = st.executeQuery();
        if (rs.next()) {
            try (Reader reportReader = rs.getClob(4).getCharacterStream();) {
                History.Event event = new History.Event();
                event.setTaskId(UUID.fromString(rs.getString(1)));
                event.setStartTimestamp(new Date(rs.getTimestamp(2).getTime()));
                event.setEndTimestamp(new Date(rs.getTimestamp(3).getTime()));
                event.setReport(deserialize(reportReader, History.Report.class));
                event.setUuid(UUID.fromString(rs.getString(5)));
                return event;
            }
        }
    } catch (IOException | SQLException ex) {
        throw new CrudlException("Error reading history event", ex);
    }

    return null;
}

From source file:com.esri.geoportal.harvester.beans.HistoryManagerBean.java

@Override
public Collection<Map.Entry<UUID, History.Event>> list() throws CrudlException {
    HashMap<UUID, History.Event> map = new HashMap<>();
    try (Connection connection = dataSource.getConnection();
            PreparedStatement st = connection
                    .prepareStatement("SELECT taskid,started,completed,report,id FROM EVENTS");) {
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            try (Reader reportReader = rs.getClob(4).getCharacterStream();) {
                History.Event event = new History.Event();
                event.setTaskId(UUID.fromString(rs.getString(1)));
                event.setStartTimestamp(new Date(rs.getTimestamp(2).getTime()));
                event.setEndTimestamp(new Date(rs.getTimestamp(3).getTime()));
                event.setReport(deserialize(reportReader, History.Report.class));
                event.setUuid(UUID.fromString(rs.getString(5)));
                map.put(event.getUuid(), event);
            }/*from w ww. ja va  2 s . com*/
        }
    } catch (IOException | SQLException ex) {
        throw new CrudlException("Error selecting broker definition", ex);
    }
    return map.entrySet();
}

From source file:com.esri.geoportal.harvester.beans.HistoryManagerBean.java

@Override
public History buildHistory(UUID taskid) throws CrudlException {
    History history = new History();
    try (Connection connection = dataSource.getConnection();
            PreparedStatement st = connection.prepareStatement(
                    "SELECT taskid,started,completed,report,id FROM EVENTS WHERE taskid = ?");) {
        st.setString(1, taskid.toString());
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            try (Reader reportReader = rs.getClob(4).getCharacterStream();) {
                History.Event event = new History.Event();
                event.setTaskId(UUID.fromString(rs.getString(1)));
                event.setStartTimestamp(new Date(rs.getTimestamp(2).getTime()));
                event.setEndTimestamp(new Date(rs.getTimestamp(3).getTime()));
                event.setReport(deserialize(reportReader, History.Report.class));
                event.setUuid(UUID.fromString(rs.getString(5)));
                history.add(event);//from  w ww .ja v a  2s . c  o  m
            }
        }
        return history;
    } catch (IOException | SQLException ex) {
        throw new CrudlException("Error selecting broker definition", ex);
    }
}

From source file:org.sakaiproject.content.impl.serialize.impl.conversion.FileSizeResourcesConversionHandler.java

public Object getSource(String id, ResultSet rs) throws SQLException {
    ResultSetMetaData metadata = rs.getMetaData();
    String rv = null;// www  .j a va  2  s.  c o  m
    switch (metadata.getColumnType(1)) {
    case Types.CLOB:
        Clob clob = rs.getClob(1);
        if (clob != null) {
            rv = clob.getSubString(1L, (int) clob.length());
        }
        break;
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
        rv = rs.getString(1);
        break;
    }
    return rv;
}

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static void streamClob(final ResultSet rs, int columnIndex, Object target, boolean close)
        throws JdbcException, SQLException, IOException {
    streamClob(rs.getClob(columnIndex), columnIndex + "", target, close);
}

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static void streamClob(final ResultSet rs, String columnName, Object target, boolean close)
        throws JdbcException, SQLException, IOException {
    streamClob(rs.getClob(columnName), columnName, target, close);
}

From source file:org.openmrs.module.sync.api.db.hibernate.usertype.SyncItemListSerializingUserType.java

/**
 * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object)
 *//*from   w ww  .j a v a  2 s  . c o  m*/
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
    if (rs.wasNull()) {
        return null;
    } else {
        Clob clob = rs.getClob(names[0]);

        if (clob == null) {
            return null;
        } else {
            // 2 Sep 2007 - Christian Allen - callen@pih.org
            // We need a workaround because clob.getSubString() and clob.length() throw an exception when used within the creating session
            //String content = clob.getSubString(1, (int)clob.length());
            // Here's the workaround:
            StringBuilder content = new StringBuilder();
            String line;

            BufferedReader br = new BufferedReader(rs.getCharacterStream(names[0]));
            try {
                while ((line = br.readLine()) != null) {
                    content.append(line);
                }
            } catch (IOException e) {
                throw new SQLException(e.toString());
            }
            // End workaround

            Collection<SyncItem> items = SyncUtil.getSyncItemsFromPayload(content.toString());

            return items;
        }
    }
}

From source file:ca.hec.cdm.jobs.ImportZC1CatalogDescriptionJob.java

public void execute(JobExecutionContext arg0) throws JobExecutionException {

    Connection connex = getZC1Connection();
    PreparedStatement ps = null;/*  w w w  . ja  v  a2 s .c  o m*/

    try {
        ps = connex.prepareStatement(ZC1_REQUEST);

        ResultSet rs = ps.executeQuery();

        while (rs.next()) {

            String koid = rs.getString(1);
            Clob htmlClob = rs.getClob(2);

            // ajouter pour la table plancours
            if (koid.substring(0, 2).equalsIgnoreCase("a-")) {
                koid = koid.substring(2);
            }

            String courseId = FormatUtils.formatCourseId(koid);

            String html = htmlClob.getSubString((long) 1, (int) htmlClob.length());
            String desc = formatHtml(html);

            if (desc != null) {
                saveInZC2(courseId, desc);
            } else {
                log.error("No description found in ZC1 for: " + courseId);
                noDesc++;
            }

        } // end while

        log.error("----------------------------------------------------------------------------------");
        log.error("FIN DE LA JOB");
        log.error("saved desc:" + savedDesc);
        log.error("unknow desc:" + unknownDesc);
        log.error("no desc found:" + noDesc);
        log.error("Description is not null:" + notNullDesc);
    } catch (SQLException sqex) {
        log.error("Error database: " + sqex.toString());
    } finally {
        try {
            ps.close();
        } catch (Exception ex) {
        }
        try {
            connex.close();
        } catch (Exception ex) {
        }
    }

}

From source file:com.textocat.textokit.commons.cpe.JdbcCollectionReader.java

private DbTuple toTuple(ResultSet rs) throws SQLException, IOException {
    String url = rs.getString(documentUrlColumn);
    String text = null;//  www.  j a  v  a2s  .  co  m
    Clob textClob = rs.getClob(textColumn);
    if (textClob != null) {
        Reader textReader = null;
        try {
            textReader = textClob.getCharacterStream();
            text = IOUtils.toString(textReader);
        } finally {
            IOUtils.closeQuietly(textReader);
            textClob.free();
        }
    }
    return new DbTuple(url, text);
}