List of usage examples for java.sql ResultSet getObject
Object getObject(String columnLabel) throws SQLException;
Gets the value of the designated column in the current row of this ResultSet
object as an Object
in the Java programming language.
From source file:com.quangphuong.crawler.dbutil.DBWrapper.java
public Object getEntityByCondition(Object entity) { String sql = selectAll.concat(entity.getClass().getSimpleName()); sql = sql.concat(whereClause);/* w w w . j a va2 s. c o m*/ Connection con = null; if (this.isDisconnect) { con = DBHandler.openConnection(); } Object result = null; try { Statement statement; if (this.isDisconnect) { statement = con.createStatement(); } else { statement = connection.createStatement(); } Field[] attributes = entity.getClass().getDeclaredFields(); int count = 0; for (Field attribute : attributes) { attribute.setAccessible(true); if (attribute.get(entity) != null) { String value = attribute.get(entity).toString(); if (count == 0) { sql = sql.concat(attribute.getName() + "=" + "\'" + value + "\'"); } else { sql = sql.concat(" AND " + attribute.getName() + "=" + "\'" + value + "\'"); } count++; } } System.out.println(sql); ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()) { List<Object> listFields = new ArrayList(); List<Class<?>> listFieldTypes = new ArrayList(); for (Field attribute : attributes) { if (!attribute.isAnnotationPresent(Ignore.class)) { Object obj = resultSet.getObject(attribute.getName()); listFields.add(obj); listFieldTypes.add(attribute.getType()); } } result = entity.getClass().getConstructor((Class<?>[]) listFieldTypes.toArray(new Class[0])) .newInstance(listFields.toArray()); } } catch (Exception ex) { Logger.getLogger(DBWrapper.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (this.isDisconnect && con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } return result; }
From source file:com.alfaariss.oa.engine.user.provisioning.storage.external.jdbc.JDBCExternalStorage.java
/** * Returns the value of the supplied field for the supplied id. * @see IExternalStorage#getField(java.lang.String, java.lang.String) *//* w ww. j ava2 s . c om*/ public Object getField(String id, String field) throws UserException { Object oValue = null; Connection oConnection = null; PreparedStatement oPreparedStatement = null; ResultSet oResultSet = null; try { StringBuffer sbQuery = new StringBuffer("SELECT "); sbQuery.append(field); sbQuery.append(" FROM "); sbQuery.append(_sTableName); sbQuery.append(" WHERE "); sbQuery.append(_sColumnUserId); sbQuery.append("=?"); oConnection = _oDataSource.getConnection(); oPreparedStatement = oConnection.prepareStatement(sbQuery.toString()); oPreparedStatement.setString(1, id); oResultSet = oPreparedStatement.executeQuery(); if (oResultSet.next()) oValue = oResultSet.getObject(field); } catch (SQLException e) { StringBuffer sbError = new StringBuffer("Could not retrieve field with name '"); sbError.append(field); sbError.append("' for id: "); sbError.append(id); _logger.error(sbError.toString(), e); throw new UserException(SystemErrors.ERROR_RESOURCE_RETRIEVE, e); } catch (Exception e) { StringBuffer sbError = new StringBuffer("Could not retrieve field with name '"); sbError.append(field); sbError.append("' for id: "); sbError.append(id); _logger.fatal(sbError.toString(), e); throw new UserException(SystemErrors.ERROR_INTERNAL, e); } finally { try { if (oResultSet != null) oResultSet.close(); } catch (Exception e) { _logger.error("Could not close resultset", e); } try { if (oPreparedStatement != null) oPreparedStatement.close(); } catch (Exception e) { _logger.error("Could not close statement", e); } try { if (oConnection != null) oConnection.close(); } catch (Exception e) { _logger.error("Could not close connection", e); } } return oValue; }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
@Override public boolean dpGetPeriod(Date t1, Date t2, Dp dp, Set<String> configs, DpGetPeriodResult result) { JDebug.out.log(Level.INFO, "dpGetPeriod: {0}-{1} {2} {3}", new Object[] { t1, t2, dp.toString(), configs.toString() }); try {//from w ww . j av a2s .c om Connection conn = dataSourceQuery.getConnection(); if (conn != null) { // select columns ArrayList<Dp> dps = createDpConfigAttrList(dp, configs); if (dps.isEmpty()) { JDebug.out.warning("dpGetPeriod without any valid config."); return false; } StringBuilder columns = new StringBuilder(); dps.forEach((Dp x) -> { String c = attrMap.get(x.getAttribute()); if (c != null) columns.append(c).append(","); }); // add the timestamp columns.append("ts AS TS"); // datapoint element_id Object tag = this.getTagOfDp(dp); if (tag == null) { JDebug.out.log(Level.SEVERE, "dpGetPeriod with invalid datapoint {0}", new Object[] { dp.toString() }); return false; } // build sql statement String sql = String.format(this.sqlSelectStmt, columns); // query data int records = 0; JDebug.out.log(Level.FINE, "dpGetPeriod SQL={0}", sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) { // tag if (tag instanceof Long) stmt.setLong(1, (Long) tag); else if (tag instanceof String) { stmt.setString(1, (String) tag); } // timerange stmt.setTimestamp(2, new java.sql.Timestamp(t1.getTime()), cal); stmt.setTimestamp(3, new java.sql.Timestamp(t2.getTime()), cal); // execute //stmt.setFetchSize(1000); ResultSet rs = stmt.executeQuery(); //ResultSetMetaData md = rs.getMetaData(); Date ts; Object value; while (rs.next()) { records++; int c = 0; ts = rs.getTimestamp("TS", cal); for (int i = 0; i < dps.size(); i++) { switch (dps.get(i).getAttribute()) { case Value: // value_number value = rs.getObject(++c); if (value != null) result.addValue(dps.get(i), ts, value); // value_string value = rs.getObject(++c); if (value != null) result.addValue(dps.get(i), ts, value); // value_timestamp value = rs.getObject(++c); if (value != null) result.addValue(dps.get(i), ts, value); break; case Status: value = rs.getObject(++c); result.addVariable(dps.get(i), ts, new Bit32Var(value)); break; case Status64: value = rs.getObject(++c); result.addVariable(dps.get(i), ts, new Bit64Var(value)); break; case Manager: case User: value = rs.getObject(++c); result.addValue(dps.get(i), ts, value); break; case Stime: value = ts; result.addValue(dps.get(i), ts, value); break; default: c++; JDebug.out.log(Level.SEVERE, "unhandeled config {0}", dps.get(i).getAttribute()); } } } } JDebug.out.log(Level.FINE, "dpGetPeriod: {0} records", records); conn.close(); return true; } else { JDebug.StackTrace(Level.SEVERE, "no connection!"); } } catch (Exception ex) { JDebug.StackTrace(Level.SEVERE, ex); } return false; }
From source file:com.ws.WS_TCS201.java
@Path("/Act") @JSONP(queryParam = "callback") @POST//w w w. j av a 2 s . co m @Produces({ "application/x-javascript" }) public String Act(@QueryParam("callback") String callback, @FormParam("state") String state, @FormParam("com") String com, @FormParam("emp") String emp, @FormParam("tcd") String tcd, @FormParam("year") String year, @FormParam("strdate") String strdate, @FormParam("enddate") String enddate, @FormParam("days") String days, @FormParam("comment") String comment, @FormParam("oldstrdate") String oldstrdate, @Context HttpServletResponse servletResponse) { JSONObject obj1 = new JSONObject(); LinkedList l1 = new LinkedList(); String cSQL = ""; int yeartkb = 0, yeartkt = 0, cnttkb = 0, cnttkt = 0; float cntdays = 0, allowdays = 0, tmplst = 0; String tmptck = "-"; String msg = ""; String yearStartDate = ""; PreparedStatement prepStmt = null; try { if (!state.equals("D") && (msg.equals(""))) { // if (state.equals("I")) { oldstrdate = "0"; } //? cSQL = " SELECT tceemp, tceapd, tceall, tcetkb, tcetkt FROM TCSTCE " + " WHERE tcecom= ? AND tceemp= ? " + " ORDER BY tceapd DESC"; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); ResultSet result = prepStmt.executeQuery(); if (result.next()) { // Object obj = result.getObject(3); allowdays = Integer.parseInt(obj.toString()); obj = result.getObject(4); yeartkb = Integer.parseInt(obj.toString()); obj = result.getObject(5); yeartkt = Integer.parseInt(obj.toString()); //*************************************************************** if (msg.equals("")) { obj = result.getObject(2); yearStartDate = obj.toString(); if (Integer.parseInt(yearStartDate) <= 20100913) { //2010.9.13?? 01/01 if ((Integer.parseInt(strdate.substring(4)) < Integer.parseInt("0101")) && (Integer.parseInt(enddate.substring(4)) >= Integer.parseInt("0101"))) { msg = "C"; } } else { //2010.9.13? ?? yearStartDate = year + yearStartDate.substring(4); if ((Integer.parseInt(strdate) < Integer.parseInt(yearStartDate)) && (Integer.parseInt(enddate) >= Integer.parseInt(yearStartDate))) { msg = "C"; } } } } else { msg = "H"; } // if ((Integer.parseInt(strdate) > Integer.parseInt(enddate)) && (msg.equals(""))) { msg = "A"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorA.html"); //return "N"; } //??***************************************************** if ((state.equals("I") || (state.equals("U") && !strdate.equals(oldstrdate))) && (msg.equals(""))) { cSQL = "SELECT * FROM TCSTCH " + "WHERE TCHCOM=? AND TCHEMP=? AND " + " ?<=TCHDED AND ?>=TCHDST "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); //prepStmt.setString(3, tcd); prepStmt.setString(3, strdate); prepStmt.setString(4, enddate); result = prepStmt.executeQuery(); if (result.next()) { msg = "B"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorB.html"); //return "N"; } } //************************************************************* /* if ((Integer.parseInt(strdate.substring(0,4)) != Integer.parseInt(enddate.substring(0,4))) && (msg.equals(""))) { msg = "C:??"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorC.html"); //return "N"; }*/ //<=- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(sdf.parse(strdate)); c2.setTime(sdf.parse(enddate)); cntdays = c2.get(Calendar.DATE) - c1.get(Calendar.DATE) + 1; if ((Integer.parseInt(days) > cntdays) && (msg.equals(""))) { msg = "E"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorE.html"); //return "N"; } //?? if (tcd.equals("B") || tcd.equals("T")) { cSQL = " SELECT SUM(CASE WHEN tchtcd = \"B\" THEN 1 ELSE 0 END ) AS sumtkb," + " SUM(CASE WHEN tchtcd = \"T\" AND tchtck = \"A\" THEN 1 WHEN tchtcd = \"T\" AND tchtck = \"B\" THEN 2 ELSE 0 END ) AS sumtkt " + " FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? AND tchyer = ? AND tchdst <> ? AND tchtcd IN (\"B\",\"T\") AND tchtck NOT IN (\"-\",\"0\") "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, year); prepStmt.setString(4, strdate); result = prepStmt.executeQuery(); if (result.next()) { Object obj = result.getObject(1); if (obj != null) { cnttkb = Integer.parseInt(obj.toString()); } obj = result.getObject(2); if (obj != null) { cnttkt = Integer.parseInt(obj.toString()); } } if (cnttkb > yeartkb || cnttkt > yeartkt) { tmptck = "0"; } } else if (tcd.equals("M") && (msg.equals(""))) { cSQL = " SELECT * FROM TCSTCH " + " WHERE tchcom = ? AND tchemp= ? AND tchtcd = ? AND tchtck NOT IN (\"-\",\"X\") "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, tcd); result = prepStmt.executeQuery(); if (result.next()) { msg = "F"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorF.html"); //return "N"; } } else if (tcd.equals("F")) { cSQL = " SELECT COUNT(*) AS times FROM TCSTCH " + " WHERE tchcom = ? AND tchemp= ? AND tchyer = ? AND tchtcd = ? AND tchtck NOT IN (\"-\",\"X\") "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, year); prepStmt.setString(4, tcd); result = prepStmt.executeQuery(); if (result.next()) { Object obj = result.getObject(1); if (obj != null && Integer.parseInt(obj.toString()) == 1) { tmptck = "X"; } } } //?******************************************************** if (tcd.equals("C") && (msg.equals(""))) { cSQL = " SELECT tchtcd, sum(tchday) AS tchday FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? " + " AND tchyer = ? AND tchdst <> ? " + " AND tchtcd = \"C\" " + " GROUP BY tchemp "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, year); prepStmt.setString(4, oldstrdate); result = prepStmt.executeQuery(); if (!result.wasNull()) { Object obj = result.getObject(2); cntdays = Integer.parseInt(obj.toString()) + Integer.parseInt(days); if (cntdays > 5) { msg = "G"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorG.html"); //return "N"; } } } if (msg.equals("")) { //<=? cSQL = " SELECT * FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? " + " AND tchyer = ? AND tchdst <> ? " + " ORDER BY tchdst DESC "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, year); prepStmt.setString(4, oldstrdate); result = prepStmt.executeQuery(); if (result.next()) { Object obj = result.getObject(9); tmplst = Float.parseFloat(obj.toString()); if (state.equals("U")) { obj = result.getObject(8); tmplst = tmplst + Integer.parseInt(obj.toString()); } tmplst = tmplst - Integer.parseInt(days); } else { tmplst = allowdays - Integer.parseInt(days); } if (tmplst < 0) { msg = "D"; //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorD.html"); //return "N"; } } } if (!msg.equals("")) { obj1.put("Msg", msg); return obj1.toString(); } // DateFormat day = new SimpleDateFormat("yyyyMMdd"); String upddate = day.format(new java.util.Date()); DateFormat time = new SimpleDateFormat("HHmmss"); String updtime = time.format(new java.util.Date()); if (state.equals("I")) { cSQL = " INSERT INTO TCSTCH VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setInt(2, Integer.parseInt(year)); prepStmt.setString(3, emp); prepStmt.setString(4, tcd); prepStmt.setFloat(5, Float.parseFloat(String.valueOf(allowdays))); prepStmt.setInt(6, Integer.parseInt(strdate)); prepStmt.setInt(7, Integer.parseInt(enddate)); prepStmt.setFloat(8, Float.parseFloat(days)); prepStmt.setFloat(9, tmplst); prepStmt.setString(10, tmptck); prepStmt.setString(11, ""); prepStmt.setString(12, comment); prepStmt.setString(13, "WS_TCS201"); prepStmt.setString(14, "TEST"); prepStmt.setInt(15, Integer.parseInt(upddate)); prepStmt.setInt(16, Integer.parseInt(updtime)); if (prepStmt.executeUpdate() == 0) { obj1.put("Msg", "SI"); return obj1.toString(); //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorI.html"); //return "N"; } } else if (state.equals("U")) { cSQL = " UPDATE TCSTCH " + " SET tchdst = ?, " + " tchded = ?, " + " tchday = ?, " + " tchlst = ?, " + " tchtxt = ?, " + " tchpg = ?, " + " tchus = ?, " + " tchdt = ?, " + " tchtm = ? " + " WHERE tchcom = ? AND tchemp = ? AND tchtcd = ? AND tchdst = ? "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setInt(1, Integer.parseInt(strdate)); prepStmt.setInt(2, Integer.parseInt(enddate)); prepStmt.setFloat(3, Float.parseFloat(days)); prepStmt.setFloat(4, tmplst); prepStmt.setString(5, comment); prepStmt.setString(6, "WS_TCS201"); prepStmt.setString(7, "TEST"); prepStmt.setInt(8, Integer.parseInt(upddate)); prepStmt.setInt(9, Integer.parseInt(updtime)); prepStmt.setString(10, com); prepStmt.setString(11, emp); prepStmt.setString(12, tcd); prepStmt.setString(13, oldstrdate); String tmptest = prepStmt.toString(); if (prepStmt.executeUpdate() == 0) { obj1.put("Msg", "SU"); return obj1.toString(); //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorU.html"); //return "N"; } } else if (state.equals("D")) { cSQL = " DELETE FROM TCSTCH " + " WHERE tchcom = ? AND tchemp = ? AND tchtcd = ? AND tchdst = ? "; prepStmt = connection.prepareStatement(cSQL); prepStmt.setString(1, com); prepStmt.setString(2, emp); prepStmt.setString(3, tcd); prepStmt.setString(4, oldstrdate); if (prepStmt.executeUpdate() == 0) { obj1.put("Msg", "SD"); return obj1.toString(); //servletResponse.sendRedirect("/RestApache/Pages/TCS211_ErrorD.html"); //return "N"; } } obj1.put("Msg", "SY"); //servletResponse.sendRedirect("/RestApache/Pages/TCS211_Success.html"); } catch (SQLException e) { prepStmt = null; e.printStackTrace(); } catch (Exception e) { prepStmt = null; e.printStackTrace(); } return obj1.toString(); //return "Y"; }
From source file:jp.primecloud.auto.tool.management.db.SQLExecuter.java
public List<Map<String, Object>> showColumns(String sql) throws SQLException, Exception { Connection con = null;// w w w . j ava 2 s . co m Statement stmt = null; ResultSet rs = null; log.info("[" + sql + "] ???"); List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); try { con = dbConnector.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); ResultSetMetaData rsMetaData = rs.getMetaData(); int size = rsMetaData.getColumnCount(); while (rs.next()) { Map<String, Object> result = new HashMap<String, Object>(); for (int i = 1; i <= size; i++) { result.put(parseColumnName(rsMetaData.getColumnName(i)), rs.getObject(i)); } results.add(result); } log.info("[" + sql + "] ????"); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SQLException(e); } catch (Exception e) { log.error(e.getMessage(), e); throw new Exception(e); } finally { try { dbConnector.closeConnection(con, stmt, rs); } catch (Exception e) { e.printStackTrace(); } } return results; }
From source file:CSVWriter.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;/*w w w . j a v a2 s . c o m*/ case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:com.alfaariss.oa.engine.attribute.gather.processor.jdbc.JDBCGatherer.java
/** * Gathers attributes from JDBC storage to the supplied attributes object. * @see com.alfaariss.oa.engine.core.attribute.gather.processor.IProcessor#process(java.lang.String, com.alfaariss.oa.api.attribute.IAttributes) *//*from w ww . j ava 2 s . c o m*/ @Override public void process(String sUserId, IAttributes oAttributes) throws AttributeException { PreparedStatement oPreparedStatement = null; ResultSet oResultSet = null; Connection oConnection = null; try { oConnection = _oDataSource.getConnection(); oPreparedStatement = oConnection.prepareStatement(_sSelectQuery); oPreparedStatement.setString(1, sUserId); oResultSet = oPreparedStatement.executeQuery(); if (oResultSet.next()) { ResultSetMetaData oResultSetMetaData = oResultSet.getMetaData(); int iCount = oResultSetMetaData.getColumnCount(); for (int i = 1; i <= iCount; i++) { String sName = oResultSetMetaData.getColumnName(i); Object oValue = oResultSet.getObject(sName); String sMappedName = _htMapper.get(sName); if (sMappedName != null) sName = sMappedName; if (oValue == null) oValue = ""; oAttributes.put(sName, oValue); } } } catch (SQLException e) { _logger.error("Could not gather attributes for user with id: " + sUserId, e); throw new AttributeException(SystemErrors.ERROR_RESOURCE_RETRIEVE); } catch (Exception e) { _logger.fatal("Could not initialize object", e); throw new AttributeException(SystemErrors.ERROR_INTERNAL); } finally { try { if (oResultSet != null) oResultSet.close(); } catch (Exception e) { _logger.error("Could not close resultset", e); } try { if (oPreparedStatement != null) oPreparedStatement.close(); } catch (Exception e) { _logger.error("Could not close statement", e); } try { if (oConnection != null) oConnection.close(); } catch (Exception e) { _logger.error("Could not disconnect prepared statement", e); } } }
From source file:com.termmed.statistics.Processor.java
/** * Prints the report.//w w w. j a v a 2 s.c o m * * @param bw the bw * @param detail the detail * @param listDescriptors * @throws Exception the exception */ private void printReport(BufferedWriter bw, OutputDetailFile detail, List<HierarchicalConfiguration> listDescriptors) throws Exception { SQLStatementExecutor executor = new SQLStatementExecutor(connection); AdditionalList[] additionalList = null; if (listDescriptors != null) { additionalList = getAdditionalList(listDescriptors); } Integer ixSctIdInReport = detail.getSctIdIndex(); if (ixSctIdInReport == null) { ixSctIdInReport = 1; } List<IReportListener> dependentReports = null; if (enableListeners) { ReportListeners reportListenersDescriptors = detail.getReportListeners(); if (reportListenersDescriptors != null) { dependentReports = initListeners(reportListenersDescriptors, detail); } } for (StoredProcedure sProc : detail.getStoredProcedure()) { executor.executeStoredProcedure(sProc, ImportManager.params, null); ResultSet rs = executor.getResultSet(); if (rs != null) { ResultSetMetaData meta = rs.getMetaData(); String fieldValue; String sctId = ""; String line; while (rs.next()) { line = ""; for (int i = 0; i < meta.getColumnCount(); i++) { if (rs.getObject(i + 1) != null) { fieldValue = rs.getObject(i + 1).toString().replaceAll(",", ",").trim(); if (ixSctIdInReport.intValue() == i) { sctId = fieldValue; } } else { fieldValue = ""; if (ixSctIdInReport.intValue() == i) { sctId = "0"; } } line += fieldValue; // bw.append(fieldValue); if (i + 1 < meta.getColumnCount()) { line += ","; // bw.append(","); } else { if (additionalList != null && detail.getCreateInterestConceptList()) { for (int ix = 0; i < additionalList.length; ix++) { line += ","; // bw.append(","); if (additionalList[ix].getIds().contains(sctId)) { line += "1"; // bw.append("1"); } else { line += "0"; // bw.append("0"); } } } bw.append(line); bw.append("\r\n"); if (dependentReports != null) { for (IReportListener dependentReport : dependentReports) { dependentReport.actionPerform(line); } } } } } meta = null; rs.close(); } } executor = null; if (dependentReports != null) { for (IReportListener dependentReport : dependentReports) { dependentReport.finalizeListener(); } } }
From source file:cz.lbenda.dataman.db.RowDesc.java
/** Load initial column value from rs */ public void loadInitialColumnValue(ColumnDesc columnDesc, ResultSet rs) throws SQLException { Object val; if (columnDesc.getDataType() == ColumnType.BIT) { val = rs.getBoolean(columnDesc.getPosition()); if (Boolean.TRUE.equals(val)) { val = (byte) 1; } else if (Boolean.FALSE.equals(val)) { val = (byte) 0; }/*from ww w.ja v a2 s. c om*/ } else if (columnDesc.getDataType() == ColumnType.BIT_ARRAY) { val = rs.getBytes(columnDesc.getPosition()); } else { val = rs.getObject(columnDesc.getPosition()); } setInitialColumnValue(columnDesc, val); }
From source file:net.fatlenny.datacitation.service.GitCitationDBService.java
private TableModel retrieveDatasetForQuery(String directory, String query, ObjectId head) throws CitationDBException { try (Connection conn = getCSVConnection(directory)) { Statement stmt = conn.createStatement(); ResultSet set = stmt.executeQuery(query); ResultSetMetaData metaData = set.getMetaData(); int columnCount = metaData.getColumnCount(); String[] columns = new String[columnCount]; for (int i = 1; i <= columnCount; i++) { columns[i - 1] = metaData.getColumnName(i); }/*from w ww. j a v a2 s.c o m*/ TableModelMetaData tableMetaData = new DefaultTableModelMetaData(new DefaultRevision(head.getName())); DefaultTableModel model = new DefaultTableModel(tableMetaData, Arrays.asList(columns)); while (set.next()) { String[] row = new String[columnCount]; for (int i = 1; i <= columnCount; i++) { row[i - 1] = (String) set.getObject(i); } model.addRow(row); } return model; } catch (SQLException e) { throw new CitationDBException(e); } }