List of usage examples for java.sql ResultSet getBytes
byte[] getBytes(String columnLabel) throws SQLException;
ResultSet
object as a byte
array in the Java programming language. From source file:ucd.denver.com.diskussioner.entityParser.parseToJson.java
public static User parseRSToUser(ResultSet rs) { System.out.println("rs rs rs" + rs); try {/*from w w w . j a va 2 s . c o m*/ User u = new User(); System.out.println("reslut set::" + rs); while (rs.next()) { System.out.println(":::"); u.setEmail(rs.getString(1)); u.setPassword(rs.getString(2)); u.setFirstName(rs.getString(3)); u.setLastName(rs.getString(4)); u.setPhoto(rs.getBytes(5)); u.setJsonUser(parseUserToJASON(u)); System.out.println("::::::" + u.getJsonUser().toString()); } return u; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:nl.nn.adapterframework.configuration.ConfigurationUtils.java
public static byte[] getConfigFromDatabase(IbisContext ibisContext, String name, String jmsRealm) throws ConfigurationException { if (StringUtils.isEmpty(jmsRealm)) { jmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm(); if (StringUtils.isEmpty(jmsRealm)) { return null; }/*w ww. j a va 2s . c o m*/ } Connection conn = null; ResultSet rs = null; FixedQuerySender qs = (FixedQuerySender) ibisContext.createBeanAutowireByName(FixedQuerySender.class); qs.setJmsRealm(jmsRealm); qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG"); qs.configure(); try { qs.open(); conn = qs.getConnection(); String query = "SELECT CONFIG FROM IBISCONFIG WHERE NAME=? AND ACTIVECONFIG= 'TRUE'"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, name); rs = stmt.executeQuery(); if (rs.next()) { return rs.getBytes(1); } } catch (SenderException e) { throw new ConfigurationException(e); } catch (JdbcException e) { throw new ConfigurationException(e); } catch (SQLException e) { throw new ConfigurationException(e); } finally { qs.close(); if (rs != null) { try { rs.close(); } catch (SQLException e) { log.warn("Could not close resultset", e); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { log.warn("Could not close connection", e); } } } return null; }
From source file:org.ut.medsavant.annotation.format.MedSavantAnnotationFormatter.java
private static void processIDFFile(File file, File dataFile, File xmlFile) throws ClassNotFoundException, IOException, SQLException, ParserConfigurationException, TransformerException, Exception { String path = file.getAbsolutePath(); Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:" + path); Statement nameStatement = conn.createStatement(); ResultSet nameResultSet = nameStatement.executeQuery("SELECT name,build FROM source"); nameResultSet.next();/*ww w . j av a2 s .c o m*/ String name = nameResultSet.getString("name"); String build = nameResultSet.getString("build"); String version = "0"; String minor_version = "0"; Statement versionStatement = conn.createStatement(); ResultSet versionResultSet = versionStatement.executeQuery("SELECT name,value FROM meta_data"); while (versionResultSet.next()) { String n = versionResultSet.getString("name"); String v = versionResultSet.getString("value"); if (n.equals("version")) { version = v; } else if (n.equals("minor_version")) { minor_version = v; } } Statement dataStatement = conn.createStatement(); ResultSet dataResultSet = dataStatement.executeQuery("SELECT * FROM interval"); AnnotationWriter aw = new AnnotationWriter(dataFile, xmlFile); aw.setName(name); aw.setReference(build); aw.setVersion(version + "." + minor_version); aw.setFieldNames(new String[] { "query_id", "start", "stop", "data" }); aw.openWriter(); int rowNum = 0; while (dataResultSet.next()) { rowNum++; if (rowNum == 2) { break; } dataResultSet.getBytes("data"); aw.addLine(new String[] { "" + dataResultSet.getInt("query_id"), "" + dataResultSet.getInt("start"), "" + dataResultSet.getInt("stop"), new String(dataResultSet.getBytes("data"), LATIN1) }); } aw.closeWriter(); aw.writeXMLSummary(); dataResultSet.close(); conn.close(); }
From source file:org.apache.jackrabbit.oak.plugins.document.rdb.RDBExport.java
private static void dumpJDBC(String url, String user, String pw, String table, String query, Format format, PrintStream out, List<String> fieldNames, RDBDocumentSerializer ser) throws SQLException { String driver = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url)); try {/*from w ww .java 2 s . c o m*/ Class.forName(driver); } catch (ClassNotFoundException ex) { System.err.println( RDBExport.class.getName() + ":attempt to load class " + driver + " failed:" + ex.getMessage()); } Connection c = DriverManager.getConnection(url, user, pw); c.setReadOnly(true); Statement stmt = c.createStatement(); String sql = "select ID, MODIFIED, MODCOUNT, CMODCOUNT, HASBINARY, DELETEDONCE, DATA, BDATA from " + table; if (query != null) { sql += " where " + query; } sql += " order by id"; ResultSet rs = stmt.executeQuery(sql); if (format == Format.JSONARRAY) { out.println("["); } else if (format == Format.CSV) { out.println(dumpFieldNames(fieldNames)); } boolean needComma = format == Format.JSONARRAY; ResultSetMetaData rsm = null; boolean idIsAscii = true; while (rs.next()) { if (rsm == null) { rsm = rs.getMetaData(); idIsAscii = !isBinaryType(rsm.getColumnType(1)); } String id = idIsAscii ? rs.getString("ID") : new String(rs.getBytes("ID"), UTF8); long modified = rs.getLong("MODIFIED"); long modcount = rs.getLong("MODCOUNT"); long cmodcount = rs.getLong("CMODCOUNT"); long hasBinary = rs.getLong("HASBINARY"); long deletedOnce = rs.getLong("DELETEDONCE"); String data = rs.getString("DATA"); byte[] bdata = rs.getBytes("BDATA"); RDBRow row = new RDBRow(id, hasBinary == 1, deletedOnce == 1, modified, modcount, cmodcount, data, bdata); StringBuilder fulljson = dumpRow(ser, id, row); if (format == Format.CSV) { out.println(asCSV(fieldNames, fulljson)); } else { fulljson = asJSON(fieldNames, fulljson); if (format == Format.JSONARRAY && needComma && !rs.isLast()) { fulljson.append(","); } out.println(fulljson); needComma = true; } } if (format == Format.JSONARRAY) { out.println("]"); } out.close(); rs.close(); stmt.close(); c.close(); }
From source file:libepg.util.db.AboutDB.java
/** * (???)/*from w ww. j ava 2 s. co m*/ * * @param conn ??DB?? * @throws java.sql.SQLException */ public static void debug_dump_table(Connection conn) throws SQLException { if (LOG.isDebugEnabled()) { final String DUMP = "SELECT * FROM " + TABLE_NAME + " ORDER BY number ASC"; ResultSet rs = conn.createStatement().executeQuery(DUMP); while (rs.next()) { StringBuilder sb1 = new StringBuilder(); sb1.append(NUMBER); sb1.append(" = "); sb1.append(rs.getInt(NUMBER)); sb1.append("####"); sb1.append(PID); sb1.append(" = "); sb1.append(rs.getInt(PID)); sb1.append("####"); sb1.append(CONTINUITY_CONTROL); sb1.append(" = "); sb1.append(rs.getInt(CONTINUITY_CONTROL)); sb1.append("####"); sb1.append(LACKFLAG); sb1.append(" = "); sb1.append(rs.getInt(LACKFLAG)); sb1.append("####"); sb1.append(PACKET); sb1.append(" = "); sb1.append(Hex.encodeHexString(rs.getBytes(PACKET))); LOG.debug(sb1.toString()); } } }
From source file:net.algem.util.CommonDao.java
public String findPhoto(int idper) throws DataAccessException { String query = "SELECT photo FROM " + PHOTO_TABLE + " WHERE idper = ?"; byte[] data = jdbcTemplate.queryForObject(query, new RowMapper<byte[]>() { @Override/*from w ww .j a va 2 s . c om*/ public byte[] mapRow(ResultSet rs, int i) throws SQLException { return rs.getBytes(1); } }, idper); return Base64.encodeBase64String(data); }
From source file:org.melati.poem.BinaryPoemType.java
protected byte[] _getRaw(ResultSet rs, int col) throws SQLException { return rs.getBytes(col); }
From source file:org.ownchan.server.persistence.typehandler.BaseGeometryTypeHandler.java
@Override public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { return toGeometry(rs.getBytes(columnIndex)); }
From source file:org.ownchan.server.persistence.typehandler.BaseGeometryTypeHandler.java
@Override public T getNullableResult(ResultSet rs, String columnName) throws SQLException { return toGeometry(rs.getBytes(columnName)); }
From source file:mercury.DigitalMediaDAO.java
public final DigitalMediaDTO getDigitalMedia(int id, String fileName) { Connection con = null;/* w ww. j a v a2 s .c o m*/ byte[] blob = null; DigitalMediaDTO dto = new DigitalMediaDTO(); try { con = getDataSource().getConnection(); String sql = " SELECT file, file_name, mime_type FROM digital_media " + " WHERE id = ? " + " AND file_name = ? ;"; PreparedStatement pst = con.prepareStatement(sql); pst.setInt(1, id); pst.setString(2, fileName); con.setAutoCommit(false); ResultSet rs = pst.executeQuery(); if (rs.next()) { blob = rs.getBytes(1); if (blob == null) { return null; } dto.setIn(new ByteArrayInputStream(blob)); dto.setLength((int) blob.length); dto.setFileName(rs.getString(2)); dto.setMimeType(rs.getString(3)); } return dto; } catch (Exception e) { log.error(e.getMessage(), e); throw new DAOException(e.getMessage()); } finally { closeConnection(con); } }