List of usage examples for java.sql ResultSet getString
String getString(String columnLabel) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:com.sql.DocketNotification.java
/** * Gather a list of notifications for items that were docketed * /* w w w .j av a2 s. c om*/ * @return */ public static List<DocketNotificationModel> getQueuedNotifications() { List<DocketNotificationModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM DocketNotifications"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { DocketNotificationModel item = new DocketNotificationModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setSendTo(rs.getString("sendTo")); item.setMessageSubject(rs.getString("emailSubject")); item.setMessageBody(rs.getString("emailBody")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:Main.java
public static Element appendResultSetToNode(Element root, String rowTag, ResultSet rs) throws SQLException { Document doc = root.getOwnerDocument(); ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); int rowCount = 0; while (rs.next()) { Element rowElement = doc.createElement(rowTag); rowElement.setAttribute("row", "" + rowCount); for (int i = 1; i <= columnCount; i++) { rowElement.setAttribute(meta.getColumnName(i), rs.getString(i)); }/*from ww w . java 2 s. com*/ rowCount++; root.appendChild(rowElement); } return root; }
From source file:com.sql.EmailOut.java
/** * Gathers current emails waiting to be sent out. * * @return List (EmailOutModel)/*from w ww . j a v a 2 s . co m*/ */ public static List<EmailOutModel> getEmailOutQueue() { List<EmailOutModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOut WHERE okToSend = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { EmailOutModel item = new EmailOutModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setCaseYear(rs.getString("caseYear")); item.setCaseType(rs.getString("caseType")); item.setCaseMonth(rs.getString("caseMonth")); item.setCaseNumber(rs.getString("caseNumber")); item.setTo(rs.getString("to")); item.setFrom(rs.getString("from")); item.setCc(rs.getString("cc")); item.setBcc(rs.getString("bcc")); item.setSubject(rs.getString("subject")); item.setBody(rs.getString("body")); item.setUserID(rs.getInt("UserID")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:Main.java
private static void addChildren(Writer writer, ResultSet rs) throws SQLException, IOException { ResultSetMetaData metaData = rs.getMetaData(); int nbColumns = metaData.getColumnCount(); StringBuffer buffer = new StringBuffer(); while (rs.next()) { buffer.setLength(0);/*from w ww.j a v a 2 s . c om*/ buffer.append("<" + metaData.getTableName(1) + ">"); for (int i = 1; i <= nbColumns; i++) { buffer.append("<" + metaData.getColumnName(i) + ">"); buffer.append(rs.getString(i)); buffer.append("</" + metaData.getColumnName(i) + ">"); } buffer.append("</" + metaData.getTableName(1) + ">"); writer.write(buffer.toString()); } }
From source file:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;/* ww w .j av a 2 s .c o m*/ else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java
public static Set discoverCatalogs(Connection conn) throws SQLException { DatabaseMetaData dbMetaData = conn.getMetaData(); ResultSet rs = null; try {/* ww w .ja v a 2s .c o m*/ Set set = new LinkedHashSet(); rs = dbMetaData.getCatalogs(); while (rs.next()) { String catalog = rs.getString(TABLE_CAT); set.add(catalog); } return set; } catch (SQLException ex) { log.error("Cannot get catalogs", ex); throw ex; } finally { if (rs != null) { try { rs.close(); } catch (Exception ex) { } } } }
From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java
public static RowMapperFactory getScalarMapper(final Type itemType, final int idx, boolean req) { if (itemType == String.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getString(idx); }/*from w w w .j av a 2s .com*/ }; } if (itemType == Integer.class || itemType == Integer.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getInt(idx); } }; } if (itemType == URL.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getURL(idx); } }; } if (itemType == BigInteger.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { final BigDecimal res = rs.getBigDecimal(idx); return res == null ? null : res.toBigInteger(); } }; } if (itemType == BigDecimal.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBigDecimal(idx); } }; } if (itemType == InputStream.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBinaryStream(idx); } }; } if (itemType == Boolean.class || itemType == Boolean.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBoolean(idx); } }; } if (itemType == Blob.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBlob(idx); } }; } if (itemType == java.sql.Date.class || itemType == java.util.Date.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getTimestamp(idx); } }; } if (itemType instanceof Class) { final Class itemClass = (Class) itemType; final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass); if (columnMapper != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return columnMapper.map(rs, idx); } }; } final Converter converter = ConvertUtils.lookup(itemClass); if (converter != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(idx); if (s == null) { return null; } return converter.convert(itemClass, s); } }; } if (Enum.class.isAssignableFrom((Class<?>) itemType)) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(idx); if (s == null) { return null; } //noinspection unchecked return Enum.valueOf((Class<Enum>) itemType, s); } }; } } if (req) { throw new IllegalArgumentException("no mapping defined for " + itemType); } return null; }
From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java
public static RowMapperFactory getScalarRowMapperFactory(final Type itemType, final String name, boolean req) { if (itemType == String.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getString(name); }/*from w ww .ja v a 2s . c om*/ }; } if (itemType == Integer.class || itemType == Integer.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getInt(name); } }; } if (itemType == URL.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getURL(name); } }; } if (itemType == BigInteger.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { final BigDecimal res = rs.getBigDecimal(name); return res == null ? null : res.toBigInteger(); } }; } if (itemType == BigDecimal.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBigDecimal(name); } }; } if (itemType == InputStream.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBinaryStream(name); } }; } if (itemType == Boolean.class || itemType == Boolean.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBoolean(name); } }; } if (itemType == Blob.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBlob(name); } }; } if (itemType == java.sql.Date.class || itemType == java.util.Date.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getTimestamp(name); } }; } if (itemType instanceof Class) { final Class itemClass = (Class) itemType; final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass); if (columnMapper != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return columnMapper.map(rs, name); } }; } final Converter converter = ConvertUtils.lookup(itemClass); if (converter != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } return converter.convert(itemClass, s); } }; } if (Enum.class.isAssignableFrom((Class<?>) itemType)) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } //noinspection unchecked return Enum.valueOf((Class<Enum>) itemType, s); } }; } } if (req) { throw new IllegalArgumentException("no mapping defined for " + itemType); } return null; }
From source file:com.keybox.manage.db.AuthDB.java
/** * checks to see if user is an admin based on auth token * * @param userId user id//from w w w . j ava 2s .c o m * @param authToken auth token string * @return user type if authorized, null if not authorized */ public static String isAuthorized(Long userId, String authToken) { String authorized = null; Connection con = null; if (authToken != null && !authToken.trim().equals("")) { try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("select * from users where enabled=true and id=? and auth_token=?"); stmt.setLong(1, userId); stmt.setString(2, authToken); ResultSet rs = stmt.executeQuery(); if (rs.next()) { authorized = rs.getString("user_type"); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } } DBUtils.closeConn(con); return authorized; }
From source file:com.sql.EmailOutInvites.java
/** * Get a list of all of the email invites awaiting to be sent. * /*from w w w . ja v a2 s . c om*/ * @return List EmailOutInvitesModel */ public static List<EmailOutInvitesModel> getQueuedEmailInvites() { List<EmailOutInvitesModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOutInvites"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { EmailOutInvitesModel item = new EmailOutInvitesModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section") == null ? "" : rs.getString("Section")); item.setToAddress(rs.getString("TOaddress") == null ? "" : rs.getString("TOaddress")); item.setCcAddress(rs.getString("CCaddress") == null ? "" : rs.getString("CCaddress")); item.setEmailBody(rs.getString("emailBody") == null ? "" : rs.getString("emailBody")); item.setCaseNumber(rs.getString("caseNumber") == null ? "" : rs.getString("caseNumber")); item.setHearingType(rs.getString("hearingType") == null ? "" : rs.getString("hearingType")); item.setHearingRoomAbv( rs.getString("hearingRoomAbv") == null ? "" : rs.getString("hearingRoomAbv")); item.setHearingDescription( rs.getString("hearingDescription") == null ? "" : rs.getString("hearingDescription")); item.setHearingStartTime( CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingStartTime"))); item.setHearingEndTime(CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingEndTime"))); item.setEmailSubject(rs.getString("emailSubject") == null ? "" : rs.getString("emailSubject")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }