List of usage examples for java.sql ResultSet getByte
byte getByte(String columnLabel) throws SQLException;
ResultSet
object as a byte
in the Java programming language. From source file:mx.edu.um.mateo.general.dao.impl.MigracionDaoHibernate.java
@Override public void hazlo(Usuario usuario) { Connection conn = null;/*from w ww . j av a 2s . com*/ Statement stmt = null; PreparedStatement buscaLibros = null; PreparedStatement buscaCCosto = null; PreparedStatement buscaCtaMayor = null; PreparedStatement buscaCuentas = null; ResultSet rs = null; ResultSet rs2 = null; Organizacion organizacion = usuario.getEmpresa().getOrganizacion(); try { conn = dataSource.getConnection(); stmt = conn.createStatement(); buscaLibros = conn.prepareStatement("select * from MATEO.CONT_LIBRO where id_ejercicio = ?"); buscaCCosto = conn.prepareStatement("select * from MATEO.CONT_CCOSTO where id_ejercicio = ?"); buscaCtaMayor = conn.prepareStatement("select * from MATEO.CONT_CTAMAYOR where id_ejercicio = ?"); buscaCuentas = conn.prepareStatement("select * from MATEO.CONT_RELACION where id_ejercicio = ?"); log.debug("Pasando ejercicios"); rs = stmt.executeQuery("select * from MATEO.CONT_EJERCICIO"); while (rs.next()) { EjercicioPK pk = new EjercicioPK(rs.getString("ID_EJERCICIO"), organizacion); Ejercicio ejercicio = new Ejercicio(); ejercicio.setId(pk); ejercicio.setMascAuxiliar(rs.getString("MASC_AUXILIAR")); ejercicio.setMascBalance(rs.getString("MASC_BALANCE")); ejercicio.setMascCcosto(rs.getString("MASC_CCOSTO")); ejercicio.setMascResultado(rs.getString("MASC_RESULTADO")); ejercicio.setNivelContable(rs.getByte("NIVEL_CONTABLE")); ejercicio.setNivelTauxiliar(rs.getByte("NIVEL_TAUXILIAR")); ejercicio.setNombre(rs.getString("NOMBRE")); ejercicio.setStatus(rs.getString("STATUS")); log.debug("Creando {}", ejercicio); currentSession().save(ejercicio); buscaLibros.setString(1, pk.getIdEjercicio()); rs2 = buscaLibros.executeQuery(); while (rs2.next()) { LibroPK libroPK = new LibroPK(ejercicio, rs2.getString("ID_LIBRO")); Libro libro = new Libro(); libro.setId(libroPK); libro.setNombre(rs2.getString("NOMBRE")); log.debug("Creando {}", libro); currentSession().save(libro); } buscaCCosto.setString(1, pk.getIdEjercicio()); rs2 = buscaCCosto.executeQuery(); while (rs2.next()) { CCostoPK cCostoPK = new CCostoPK(ejercicio, rs2.getString("ID_CCOSTO")); CentroCosto centroCosto = new CentroCosto(); centroCosto.setId(cCostoPK); centroCosto.setDetalle(rs2.getString("DETALLE")); centroCosto.setIniciales(rs2.getString("INICIALES")); centroCosto.setNombre(rs2.getString("NOMBRE")); log.debug("Creando {}", centroCosto); currentSession().save(centroCosto); } buscaCtaMayor.setString(1, pk.getIdEjercicio()); rs2 = buscaCtaMayor.executeQuery(); while (rs2.next()) { CtaMayorPK ctaMayorPK = new CtaMayorPK(ejercicio, rs2.getString("ID_CTAMAYOR"), rs2.getString("TIPO_CUENTA")); CuentaMayor ctaMayor = new CuentaMayor(); ctaMayor.setId(ctaMayorPK); ctaMayor.setNombre(rs2.getString("NOMBRE")); ctaMayor.setNombreFiscal(rs2.getString("NOMBREFISCAL")); ctaMayor.setDetalle(rs2.getString("DETALLE")); ctaMayor.setAviso(rs2.getString("AVISO")); ctaMayor.setAuxiliar(rs2.getString("AUXILIAR")); ctaMayor.setIva(rs2.getString("IVA")); ctaMayor.setPctIVA(rs2.getLong("PCTIVA")); ctaMayor.setDetaller(rs2.getString("DETALLER")); log.debug("Creando {}", ctaMayor); currentSession().save(ctaMayor); } // buscaCuentas.setString(1, pk.getIdEjercicio()); // rs2 = buscaCuentas.executeQuery(); // while(rs2.next()) { // CuentaPK cuentaPK = new CuentaPK(ejercicio, // rs2.getString("ID_CTAMAYOR"), rs2.getString("TIPO_CUENTA"), // rs2.getString("ID_CCOSTO"), rs2.getString("ID_AUXILIAR")); // Cuenta cuenta = new Cuenta(); // cuenta.setId(cuentaPK); // cuenta.setNaturaleza(rs2.getString("NATURALEZA")); // cuenta.setNombre(rs2.getString("NOMBRE")); // cuenta.setStatus(rs2.getString("STATUS")); // log.debug("Creando {}", cuenta); // currentSession().save(cuenta); // } } currentSession().flush(); } catch (SQLException e) { log.error("Errores en la migracion", e); } finally { try { if (rs2 != null) { rs2.close(); } if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } if (buscaLibros != null) { buscaLibros.close(); } if (buscaCCosto != null) { buscaCCosto.close(); } if (buscaCtaMayor != null) { buscaCtaMayor.close(); } if (buscaCuentas != null) { buscaCuentas.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { log.error("Problema al cerrar conexiones", e); } } }
From source file:com.l2jfree.gameserver.datatables.SkillTreeTable.java
private SkillTreeTable() { int classId = 0; int count = 0; Connection con = null;// ww w . j av a 2s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement("SELECT * FROM class_list ORDER BY id"); ResultSet classlist = statement.executeQuery(); Map<Integer, L2SkillLearn> map; int parentClassId; L2SkillLearn skillLearn; while (classlist.next()) { map = new FastMap<Integer, L2SkillLearn>(); parentClassId = classlist.getInt("parent_id"); classId = classlist.getInt("id"); PreparedStatement statement2 = con.prepareStatement( "SELECT class_id, skill_id, level, name, sp, min_level FROM skill_trees where class_id=? ORDER BY skill_id, level"); statement2.setInt(1, classId); ResultSet skilltree = statement2.executeQuery(); if (parentClassId != -1) { Map<Integer, L2SkillLearn> parentMap = getSkillTrees()[parentClassId]; map.putAll(parentMap); } int prevSkillId = -1; while (skilltree.next()) { int id = skilltree.getInt("skill_id"); int lvl = skilltree.getInt("level"); String name = skilltree.getString("name"); int minLvl = skilltree.getInt("min_level"); int cost = skilltree.getInt("sp"); if (prevSkillId != id) prevSkillId = id; skillLearn = new L2SkillLearn(id, lvl, minLvl, name, cost, 0, 0); map.put(SkillTable.getSkillUID(id, lvl), skillLearn); } getSkillTrees()[classId] = map; skilltree.close(); statement2.close(); count += map.size(); if (_log.isDebugEnabled()) _log.info("SkillTreeTable: skill tree for class " + classId + " has " + map.size() + " skills"); } classlist.close(); statement.close(); } catch (Exception e) { _log.fatal("Error while creating skill tree (Class ID " + classId + "):", e); } _log.info("SkillTreeTable: Loaded " + count + " skills."); //Skill tree for fishing skill (from Fisherman) int count2 = 0; int count3 = 0; try { _fishingSkillTrees = new FastList<L2SkillLearn>(); _expandDwarfCraftSkillTrees = new FastList<L2SkillLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT skill_id, level, name, sp, min_level, costid, cost, isfordwarf FROM fishing_skill_trees ORDER BY skill_id, level"); ResultSet skilltree2 = statement.executeQuery(); int prevSkillId = -1; while (skilltree2.next()) { int id = skilltree2.getInt("skill_id"); int lvl = skilltree2.getInt("level"); String name = skilltree2.getString("name"); int minLvl = skilltree2.getInt("min_level"); int cost = skilltree2.getInt("sp"); int costId = skilltree2.getInt("costid"); int costCount = skilltree2.getInt("cost"); int isDwarven = skilltree2.getInt("isfordwarf"); if (prevSkillId != id) prevSkillId = id; L2SkillLearn skill = new L2SkillLearn(id, lvl, minLvl, name, cost, costId, costCount); if (isDwarven == 0) _fishingSkillTrees.add(skill); else _expandDwarfCraftSkillTrees.add(skill); } skilltree2.close(); statement.close(); count2 = _fishingSkillTrees.size(); count3 = _expandDwarfCraftSkillTrees.size(); } catch (Exception e) { _log.fatal("Error while creating fishing skill table: ", e); } int count4 = 0; try { _enchantSkillTrees = new FastMap<Integer, L2EnchantSkillLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT skill_id, level, base_lvl, sp, min_skill_lvl, exp, success_rate76, success_rate77, success_rate78, success_rate79, success_rate80, success_rate81, success_rate82, success_rate83, success_rate84, success_rate85 FROM enchant_skill_trees ORDER BY skill_id, level"); ResultSet skilltree3 = statement.executeQuery(); int prevSkillId = -1; while (skilltree3.next()) { int id = skilltree3.getInt("skill_id"); int lvl = skilltree3.getInt("level"); int baseLvl = skilltree3.getInt("base_lvl"); int minSkillLvl = skilltree3.getInt("min_skill_lvl"); int sp = skilltree3.getInt("sp"); int exp = skilltree3.getInt("exp"); byte rate76 = skilltree3.getByte("success_rate76"); byte rate77 = skilltree3.getByte("success_rate77"); byte rate78 = skilltree3.getByte("success_rate78"); byte rate79 = skilltree3.getByte("success_rate79"); byte rate80 = skilltree3.getByte("success_rate80"); byte rate81 = skilltree3.getByte("success_rate81"); byte rate82 = skilltree3.getByte("success_rate82"); byte rate83 = skilltree3.getByte("success_rate83"); byte rate84 = skilltree3.getByte("success_rate84"); byte rate85 = skilltree3.getByte("success_rate85"); if (prevSkillId != id) prevSkillId = id; L2EnchantSkillLearn skill = _enchantSkillTrees.get(id); if (skill == null) { skill = new L2EnchantSkillLearn(id, baseLvl); _enchantSkillTrees.put(id, skill); } EnchantSkillDetail esd = new EnchantSkillDetail(lvl, minSkillLvl, sp, exp, rate76, rate77, rate78, rate79, rate80, rate81, rate82, rate83, rate84, rate85); skill.addEnchantDetail(esd); } skilltree3.close(); statement.close(); count4 = _enchantSkillTrees.size(); } catch (Exception e) { _log.fatal("Error while creating enchant skill table: ", e); } int count5 = 0; try { _pledgeSkillTrees = new FastList<L2PledgeSkillLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT skill_id, level, name, clan_lvl, repCost, itemId, itemCount FROM pledge_skill_trees ORDER BY skill_id, level"); ResultSet skilltree4 = statement.executeQuery(); int prevSkillId = -1; while (skilltree4.next()) { int id = skilltree4.getInt("skill_id"); int lvl = skilltree4.getInt("level"); String name = skilltree4.getString("name"); int baseLvl = skilltree4.getInt("clan_lvl"); int sp = skilltree4.getInt("repCost"); int itemId = skilltree4.getInt("itemId"); long itemCount = skilltree4.getLong("itemCount"); if (prevSkillId != id) prevSkillId = id; L2PledgeSkillLearn skill = new L2PledgeSkillLearn(id, lvl, baseLvl, name, sp, itemId, itemCount); _pledgeSkillTrees.add(skill); } skilltree4.close(); statement.close(); count5 = _pledgeSkillTrees.size(); } catch (Exception e) { _log.fatal("Error while creating pledge skill table: ", e); } int count6 = 0; try { _transformSkillTrees = new FastList<L2TransformSkillLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT race_id, skill_id, item_id, level, name, sp, min_level FROM transform_skill_trees ORDER BY race_id, skill_id, level"); ResultSet skilltree5 = statement.executeQuery(); int prevSkillId = -1; while (skilltree5.next()) { int race_id = skilltree5.getInt("race_id"); int skill_id = skilltree5.getInt("skill_id"); int item_id = skilltree5.getInt("item_id"); int level = skilltree5.getInt("level"); String name = skilltree5.getString("name"); int sp = skilltree5.getInt("sp"); int min_level = skilltree5.getInt("min_level"); if (prevSkillId != skill_id) prevSkillId = skill_id; L2TransformSkillLearn skill = new L2TransformSkillLearn(race_id, skill_id, item_id, level, name, sp, min_level); _transformSkillTrees.add(skill); } skilltree5.close(); statement.close(); count6 = _transformSkillTrees.size(); } catch (Exception e) { _log.fatal("Error while creating Transformation skill table ", e); } int count7 = 0; try { _specialSkillTrees = new FastList<L2SkillLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT skill_id, level, name, costid, cost FROM special_skill_trees ORDER BY skill_id, level"); ResultSet skilltree6 = statement.executeQuery(); int prevSkillId = -1; while (skilltree6.next()) { int id = skilltree6.getInt("skill_id"); int lvl = skilltree6.getInt("level"); String name = skilltree6.getString("name"); int costId = skilltree6.getInt("costid"); int costCount = skilltree6.getInt("cost"); if (prevSkillId != id) prevSkillId = id; L2SkillLearn skill = new L2SkillLearn(id, lvl, 0, name, 0, costId, costCount); _specialSkillTrees.add(skill); } skilltree6.close(); statement.close(); count7 = _specialSkillTrees.size(); } catch (Exception e) { _log.fatal("Error while creating SpecialSkillTree skill table ", e); } int count8 = 0; try { _certificationSkillsTrees = new FastList<L2CertificationSkillsLearn>(); con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT skill_id, item_id, level, name FROM certification_skill_trees ORDER BY skill_id, level"); ResultSet skilltree6 = statement.executeQuery(); int prevSkillId = -1; while (skilltree6.next()) { int skill_id = skilltree6.getInt("skill_id"); int item_id = skilltree6.getInt("item_id"); int level = skilltree6.getInt("level"); String name = skilltree6.getString("name"); if (prevSkillId != skill_id) prevSkillId = skill_id; L2CertificationSkillsLearn skill = new L2CertificationSkillsLearn(skill_id, item_id, level, name); _certificationSkillsTrees.add(skill); } skilltree6.close(); statement.close(); count8 = _certificationSkillsTrees.size(); } catch (Exception e) { _log.fatal("Error while creating Certification skill table ", e); } finally { L2DatabaseFactory.close(con); } _log.info("FishingSkillTreeTable: Loaded " + count2 + " general skills."); _log.info("DwarvenSkillTreeTable: Loaded " + count3 + " dwarven skills."); _log.info("EnchantSkillTreeTable: Loaded " + count4 + " enchant skills."); _log.info("PledgeSkillTreeTable: Loaded " + count5 + " pledge skills."); _log.info("TransformSkillTreeTable: Loaded " + count6 + " transform skills."); _log.info("SpecialSkillTreeTable: Loaded " + count7 + " special skills"); _log.info("CertificationSkillsTreeTable: Loaded " + count8 + " certification skills."); }
From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>//from www . j ava2 s . co m * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(byte[].class)) { return rs.getBytes(index); } else { return rs.getObject(index); } }
From source file:org.plasma.sdo.access.provider.jdbc.JDBCDataConverter.java
public Object fromJDBCDataType(ResultSet rs, int columnIndex, int sourceType, PlasmaProperty targetProperty) throws SQLException { Object result = null;//from ww w . ja va 2s. co m if (targetProperty.getType().isDataType()) { DataType targetDataType = DataType.valueOf(targetProperty.getType().getName()); switch (targetDataType) { case String: case URI: case Month: case MonthDay: case Day: case Time: case Year: case YearMonth: case YearMonthDay: case Duration: result = rs.getString(columnIndex); break; case Date: java.sql.Timestamp ts = rs.getTimestamp(columnIndex); if (ts != null) result = new java.util.Date(ts.getTime()); break; case DateTime: ts = rs.getTimestamp(columnIndex); if (ts != null) result = new java.util.Date(ts.getTime()); break; case Decimal: result = rs.getBigDecimal(columnIndex); break; case Bytes: result = rs.getBytes(columnIndex); break; case Byte: result = rs.getByte(columnIndex); break; case Boolean: result = rs.getBoolean(columnIndex); break; case Character: result = rs.getInt(columnIndex); break; case Double: result = rs.getDouble(columnIndex); break; case Float: result = rs.getFloat(columnIndex); break; case Int: result = rs.getInt(columnIndex); break; case Integer: result = new BigInteger(rs.getString(columnIndex)); break; case Long: result = rs.getLong(columnIndex); break; case Short: result = rs.getShort(columnIndex); break; case Strings: String value = rs.getString(columnIndex); String[] values = value.split("\\s"); List<String> list = new ArrayList<String>(values.length); for (int i = 0; i < values.length; i++) list.add(values[i]); // what no Java 5 sugar for this ?? result = list; break; case Object: default: result = rs.getObject(columnIndex); break; } } else { // FIXME: or get the opposite containing type // of the property and get its pri-key(s) result = rs.getObject(columnIndex); } return result; }
From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * //from www . j av a2s . com * <p> * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return (rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return (rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return (rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return (rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return (rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return (rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return (rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else { return rs.getObject(index); } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/*from w w w . j ava 2 s .com*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:org.openiot.gsn.wrappers.JDBCWrapper.java
public void run() { DataEnumerator data;/*from w ww .j a v a 2 s .co m*/ try { Thread.sleep(2000); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } Connection conn = null; ResultSet resultSet = null; while (isActive()) { try { conn = sm.getConnection(); StringBuilder query = new StringBuilder("select * from ").append(table_name) .append(" where timed > " + latest_timed + " limit 0," + buffer_size); resultSet = sm.executeQueryWithResultSet(query, conn); //logger.debug(query); while (resultSet.next()) { Serializable[] output = new Serializable[this.getOutputFormat().length]; long pk = resultSet.getLong(1); long timed = resultSet.getLong(2); //logger.warn("pk => "+ pk); //logger.warn("timed => "+ timed); for (int i = 0; i < dataFieldsLength; i++) { switch (dataFieldTypes[i]) { case DataTypes.VARCHAR: case DataTypes.CHAR: output[i] = resultSet.getString(i + 3); break; case DataTypes.INTEGER: output[i] = resultSet.getInt(i + 3); break; case DataTypes.TINYINT: output[i] = resultSet.getByte(i + 3); break; case DataTypes.SMALLINT: output[i] = resultSet.getShort(i + 3); break; case DataTypes.DOUBLE: output[i] = resultSet.getDouble(i + 3); break; case DataTypes.BIGINT: output[i] = resultSet.getLong(i + 3); break; case DataTypes.BINARY: output[i] = resultSet.getBytes(i + 3); break; } //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]); } StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed); latest_timed = se.getTimeStamp(); //logger.warn(" Latest => " + latest_timed); this.postStreamElement(se); updateCheckPointFile(latest_timed); //logger.warn(se); } } catch (java.io.IOException e) { logger.error(e.getMessage(), e); } catch (SQLException e) { logger.error(e.getMessage(), e); } finally { sm.close(resultSet); sm.close(conn); } try { Thread.sleep(rate); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } }
From source file:gsn.wrappers.JDBCWrapper.java
public void run() { DataEnumerator data;/*from w ww. jav a 2 s.c o m*/ try { Thread.sleep(2000); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } Connection conn = null; ResultSet resultSet = null; while (isActive()) { try { conn = sm.getConnection(); StringBuilder query = new StringBuilder("select * from ").append(table_name) .append(" where timed > " + latest_timed + " limit 0," + buffer_size); resultSet = sm.executeQueryWithResultSet(query, conn); //logger.debug(query); while (resultSet.next()) { Serializable[] output = new Serializable[this.getOutputFormat().length]; long pk = resultSet.getLong(1); long timed = resultSet.getLong(2); //logger.warn("pk => "+ pk); //logger.warn("timed => "+ timed); for (int i = 0; i < dataFieldsLength; i++) { switch (dataFieldTypes[i]) { case DataTypes.VARCHAR: case DataTypes.CHAR: output[i] = resultSet.getString(i + 3); break; case DataTypes.INTEGER: output[i] = resultSet.getInt(i + 3); break; case DataTypes.TINYINT: output[i] = resultSet.getByte(i + 3); break; case DataTypes.SMALLINT: output[i] = resultSet.getShort(i + 3); break; case DataTypes.DOUBLE: output[i] = resultSet.getDouble(i + 3); break; case DataTypes.FLOAT: output[i] = resultSet.getFloat(i + 3); break; case DataTypes.BIGINT: output[i] = resultSet.getLong(i + 3); break; case DataTypes.BINARY: output[i] = resultSet.getBytes(i + 3); break; } //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]); } StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed); latest_timed = se.getTimeStamp(); //logger.warn(" Latest => " + latest_timed); this.postStreamElement(se); updateCheckPointFile(latest_timed); //logger.warn(se); } } catch (java.io.IOException e) { logger.error(e.getMessage(), e); } catch (SQLException e) { logger.error(e.getMessage(), e); } finally { sm.close(resultSet); sm.close(conn); } try { Thread.sleep(rate); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } }
From source file:org.openiot.gsn.wrappers.TetraedreNMCWrapper.java
public void run() { DataEnumerator data;/*from ww w. j a v a 2 s.c om*/ try { Thread.sleep(2000); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } Connection conn = null; ResultSet resultSet = null; while (isActive()) { try { conn = sm.getConnection(); StringBuilder query = new StringBuilder("select * from ").append(table_name).append( " where timestamp*1000 > " + latest_timed + " order by timestamp limit 0," + buffer_size); resultSet = sm.executeQueryWithResultSet(query, conn); //logger.debug(query); while (resultSet.next()) { Serializable[] output = new Serializable[this.getOutputFormat().length]; //long pk = resultSet.getLong(1); long timed = resultSet.getLong(1) * 1000; //logger.warn("pk => "+ pk); //logger.warn("timed => "+ timed); for (int i = 0; i < dataFieldsLength; i++) { switch (dataFieldTypes[i]) { case DataTypes.VARCHAR: case DataTypes.CHAR: output[i] = resultSet.getString(i + 1); break; case DataTypes.INTEGER: output[i] = resultSet.getInt(i + 1); break; case DataTypes.TINYINT: output[i] = resultSet.getByte(i + 1); break; case DataTypes.SMALLINT: output[i] = resultSet.getShort(i + 1); break; case DataTypes.DOUBLE: output[i] = resultSet.getDouble(i + 1); break; case DataTypes.BIGINT: output[i] = resultSet.getLong(i + 1); break; case DataTypes.BINARY: output[i] = resultSet.getBytes(i + 1); break; } //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]); } StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed); latest_timed = se.getTimeStamp(); //logger.warn(" Latest => " + latest_timed); this.postStreamElement(se); updateCheckPointFile(latest_timed); //logger.warn(se); } } catch (IOException e) { logger.error(e.getMessage(), e); } catch (SQLException e) { logger.error(e.getMessage(), e); } finally { sm.close(resultSet); sm.close(conn); } try { Thread.sleep(rate); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } }
From source file:gsn.wrappers.TetraedreNMCWrapper.java
public void run() { DataEnumerator data;/*w w w . j av a 2 s . c o m*/ try { Thread.sleep(2000); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } Connection conn = null; ResultSet resultSet = null; while (isActive()) { try { conn = sm.getConnection(); StringBuilder query = new StringBuilder("select * from ").append(table_name).append( " where timestamp*1000 > " + latest_timed + " order by timestamp limit 0," + buffer_size); resultSet = sm.executeQueryWithResultSet(query, conn); //logger.debug(query); while (resultSet.next()) { Serializable[] output = new Serializable[this.getOutputFormat().length]; //long pk = resultSet.getLong(1); long timed = resultSet.getLong(1) * 1000; //logger.warn("pk => "+ pk); //logger.warn("timed => "+ timed); for (int i = 0; i < dataFieldsLength; i++) { switch (dataFieldTypes[i]) { case DataTypes.VARCHAR: case DataTypes.CHAR: output[i] = resultSet.getString(i + 1); break; case DataTypes.INTEGER: output[i] = resultSet.getInt(i + 1); break; case DataTypes.TINYINT: output[i] = resultSet.getByte(i + 1); break; case DataTypes.SMALLINT: output[i] = resultSet.getShort(i + 1); break; case DataTypes.DOUBLE: output[i] = resultSet.getDouble(i + 1); break; case DataTypes.FLOAT: output[i] = resultSet.getFloat(i + 1); break; case DataTypes.BIGINT: output[i] = resultSet.getLong(i + 1); break; case DataTypes.BINARY: output[i] = resultSet.getBytes(i + 1); break; } //logger.warn(i+" (type: "+dataFieldTypes[i]+" ) => "+output[i]); } StreamElement se = new StreamElement(dataFieldNames, dataFieldTypes, output, timed); latest_timed = se.getTimeStamp(); //logger.warn(" Latest => " + latest_timed); this.postStreamElement(se); updateCheckPointFile(latest_timed); //logger.warn(se); } } catch (IOException e) { logger.error(e.getMessage(), e); } catch (SQLException e) { logger.error(e.getMessage(), e); } finally { sm.close(resultSet); sm.close(conn); } try { Thread.sleep(rate); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } }