List of usage examples for java.sql ResultSet wasNull
boolean wasNull() throws SQLException;
NULL
. From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java
public static String getNullableString(ResultSet reader, int colidx) { try {/*from ww w .j av a 2 s. c om*/ String val = reader.getString(colidx); if (reader.wasNull()) { return (null); } else { return (val); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccXMsgClientSchema.class, "getNullableString", e); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java
public static BigDecimal getNullableUInt64(ResultSet reader, int colidx) { try {//w w w .j a v a2 s . com String strval = reader.getString(colidx); if (reader.wasNull() || (strval == null) || (strval.length() <= 0)) { return (null); } else { BigDecimal retval = new BigDecimal(strval); return (retval); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccXMsgClientSchema.class, "getNullableUInt64", e); } }
From source file:dbs_project.util.Utils.java
public static String resultSetToHtmlTable(java.sql.ResultSet rs) throws SQLException { int rowCount = 0; final StringBuilder result = new StringBuilder(); result.append("<P ALIGN='center'>\n<TABLE BORDER=1>\n"); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); //header//from w ww. j a v a2 s . co m result.append("\t<TR>\n"); for (int i = 0; i < columnCount; ++i) { result.append("\t\t<TH>").append(rsmd.getColumnLabel(i + 1)).append("</TH>\n"); } result.append("\t</TR>\n"); //data while (rs.next()) { ++rowCount; result.append("\t<TR>\n"); for (int i = 0; i < columnCount; ++i) { String value = rs.getString(i + 1); if (rs.wasNull()) { value = "<null>"; } result.append("\t\t<TD>").append(value).append("</TD>\n"); } result.append("\t</TR>\n"); } result.append("</TABLE>\n</P>\n"); return result.toString(); }
From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasLongColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { rs.getLong(name);//from ww w . ja v a 2 s . c o m return !rs.wasNull(); } return false; }
From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasDateColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { rs.getDate(name);/*from w ww .jav a2 s.c o m*/ return !rs.wasNull(); } return false; }
From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasBooleanColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { rs.getBoolean(name);/*from w w w . j av a 2 s. c o m*/ return !rs.wasNull(); } return false; }
From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasStringColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { String value = rs.getString(name); return !rs.wasNull() && value != null; }//w w w .j a va 2 s. co m return false; }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.data.DBConnector.java
/** Checks if name='value' exists in the given table. If it does, returns its id. If not * inserts it into the table and returns the generated id. Works only for tables that * generate IDs, only for VARCHAR values, and only for tables that have only two columns: * ID and some VARCHAR column (given by name) */ public int insertIfDNE(String table, String name, String value) { Connection conn = null;// w w w .j ava 2 s. c om Object[] results = null; try { conn = getConnection(); String query = "select id from " + table + " where " + name + "='" + value + "'"; results = executeQuery(query, conn); int id = -1; //Check if name=value is there -- if so, return its id if (results != null) { ResultSet rs = (ResultSet) results[0]; if (!rs.wasNull()) { rs.last(); int size = rs.getRow(); if (size > 0) { id = rs.getInt("id"); return id; } } } //If the security was not found then add it and return the generated id String update = "insert into " + table + " values(0, '" + value + "')"; results = executeUpdate(update, conn); ResultSet rs = (ResultSet) results[0]; rs.next(); id = rs.getInt(1); return id; } catch (SQLException e) { log.error("Failed to perform a 'add if does not exist' table insert: " + e); return -1; } finally { closeQuery(results, conn); } }
From source file:net.sourceforge.vulcan.spring.jdbc.ChangeSetQuery.java
@Override protected ChangeSetDto mapRow(ResultSet rs, int rowNumber) throws SQLException { final ChangeSetDto dto = new ChangeSetDto(); dto.setMessage(rs.getString("message")); dto.setAuthorName(rs.getString("author")); dto.setAuthorEmail(rs.getString("author_email")); dto.setRevisionLabel(rs.getString("revision_label")); final Timestamp timestamp = rs.getTimestamp("commit_timestamp"); if (!rs.wasNull()) { dto.setTimestamp(new Date(timestamp.getTime())); }//from w w w. ja va 2s .c om int buildId = rs.getInt("build_id"); int changeSetId = rs.getInt("change_set_id"); final List<ModifiedPathDto> paths = modifiedPathQuery.queryModifiedPaths(buildId, changeSetId); dto.setModifiedPaths(paths); return dto; }
From source file:net.sourceforge.vulcan.spring.jdbc.BuildMessagesQuery.java
@Override protected JdbcBuildMessageDto mapRow(ResultSet rs, int rowNumber) throws SQLException { final JdbcBuildMessageDto dto = new JdbcBuildMessageDto(); dto.setMessageType(BuildMessageType.fromRdbmsValue(rs.getString("message_type"))); dto.setMessage(rs.getString("message")); dto.setFile(rs.getString("file")); dto.setCode(rs.getString("code")); final int lineNumber = rs.getInt("line_number"); if (!rs.wasNull()) { dto.setLineNumber(lineNumber);//from w ww . j a v a 2 s. c o m } return dto; }