List of usage examples for java.sql ResultSet getBoolean
boolean getBoolean(String columnLabel) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:org.cbarrett.lcbo.db.mapper.LCBOProductExtractor.java
@Override public Product extractData(ResultSet rs) throws SQLException { Product prod = new Product(); prod.setId(rs.getString(1));//w w w .jav a 2s.c o m prod.setProducer_name(rs.getString(2)); prod.setName(rs.getString(3)); prod.setDescription(rs.getString(4)); prod.setAlcohol_content(rs.getInt(5)); prod.setIs_dead(rs.getBoolean(6)); prod.setIs_discontinued(rs.getBoolean(7)); if (rs.getString(8) != null) { prod.setStock_type(StockType.valueOf(rs.getString(8))); } prod.setPrice_in_cents(rs.getInt(9)); prod.setOrigin(rs.getString(10)); prod.setPrimary_category(rs.getString(11)); prod.setSecondary_category(rs.getString(12)); if (rs.getTimestamp(13) != null) { prod.setReleasedOn(new DateTime((rs.getTimestamp(13)).getTime())); } prod.setInventory_count(rs.getInt(14)); if (rs.getTimestamp(15) != null) { prod.setUpdatedAt(new DateTime((rs.getTimestamp(15)).getTime())); } prod.setImageThumbUrl(rs.getString(15)); prod.setImageUrl(rs.getString(16)); return prod; }
From source file:com.googlecode.flyway.core.dbsupport.h2.H2DbSupport.java
public String getCurrentSchema() throws SQLException { ResultSet resultSet = null; String schema = null;//from w ww.ja va 2 s .c om try { resultSet = jdbcTemplate.getMetaData().getSchemas(); while (resultSet.next()) { if (resultSet.getBoolean("IS_DEFAULT")) { schema = resultSet.getString("TABLE_SCHEM"); break; } } } finally { JdbcUtils.closeResultSet(resultSet); } return schema; }
From source file:com.pagodalabs.institute.dao.impl.CourseDAOImpl.java
@Override public List<Course> getAll() { String sql = "SELECT * FROM courses"; List<Course> courseList = jdbcTemplate.query(sql, new RowMapper<Course>() { @Override/* w w w .jav a2 s .com*/ public Course mapRow(ResultSet rs, int i) throws SQLException { Course course = new Course(); course.setId(rs.getInt("course_id")); course.setName(rs.getString("course_name")); course.setDescription(rs.getString("course_description")); course.setStatus(rs.getBoolean("status")); return course; } }); return courseList; }
From source file:de.klemp.middleware.controller.Controller.java
private static synchronized void ActiveDevicesToList() { deviceActive.clear();/*from w ww . j ava 2s . c o m*/ createDBConnection(); try { PreparedStatement st = conn.prepareStatement("select * from \"OutputDevices\" ;"); ResultSet r = st.executeQuery(); while (r.next()) { String key = r.getString("class") + "," + r.getString("topic"); deviceActive.put(key, r.getBoolean("enabled")); } } catch (SQLException e) { logger.error("SQL Exception in ActiveDevicesToList", e); } closeDBConnection(); }
From source file:mvc.dao.TarefaDAO.java
public Tarefa buscarTarefaPorId(Long id) { String sql = "select * from tarefas where id = ? "; try (PreparedStatement stmt = connection.prepareStatement(sql)) { stmt.setLong(1, id);//from w w w .ja v a 2 s . com ResultSet rs = stmt.executeQuery(); Tarefa tarefa = new Tarefa(); if (rs.next()) { tarefa.setId(rs.getLong("id")); tarefa.setDescricao(rs.getString("descricao")); tarefa.setFinalizado(rs.getBoolean("finalizado")); //montando data Calendar data = Calendar.getInstance(); if (rs.getDate("dataFinalizacao") != null) { data.setTime(rs.getDate("dataFinalizacao")); System.out.println("data"); tarefa.setDataFinalizacao(data); } } return tarefa; } catch (SQLException e) { throw new RuntimeException(e); } }
From source file:mvc.dao.TarefaDAO.java
public List<Tarefa> listarTarefas() { List<Tarefa> listaTarefas = new ArrayList<Tarefa>(); String sql = "select * from tarefas order by descricao"; try (PreparedStatement stmt = connection.prepareStatement(sql)) { ResultSet rs = stmt.executeQuery(); while (rs.next()) { Tarefa tarefa = new Tarefa(); tarefa.setId(rs.getLong("id")); tarefa.setDescricao(rs.getString("descricao")); tarefa.setFinalizado(rs.getBoolean("finalizado")); //montando data Calendar data = Calendar.getInstance(); if (rs.getDate("dataFinalizacao") != null) { data.setTime(rs.getDate("dataFinalizacao")); tarefa.setDataFinalizacao(data); }/* w w w . j a v a2 s. c om*/ listaTarefas.add(tarefa); } } catch (SQLException e) { throw new RuntimeException(e); } return listaTarefas; }
From source file:com.magrocode.bm.service.dao.jdbc.SmtpConfigDaoImpl.java
@Override public SmtpConfigTo[] getAll() { String sql = "SELECT * FROM SMTP_CONFIG;"; return (SmtpConfigTo[]) jdbcTemplate.query(sql, new RowMapper<SmtpConfigTo>() { @Override// w ww . ja v a 2s.c om public SmtpConfigTo mapRow(ResultSet rs, int i) throws SQLException { SmtpConfigTo c = new SmtpConfigTo(); c.setId(rs.getInt("SMTP_CONFIG_ID")); c.setCompanya_id(rs.getInt("COMPANYA_ID")); c.setHost(rs.getString("SMTP_HOST")); c.setPort(rs.getInt("SMTP_PORT")); c.setAuth(rs.getBoolean("SMTP_AUTH")); c.setEmail(rs.getString("SMTP_EMAIL")); c.setUsername(rs.getString("SMTP_USERNAME")); c.setPassword(rs.getString("SMTP_PASSWORD")); return c; } }).toArray(new SmtpConfigTo[] {}); }
From source file:com.dsclab.loader.export.DBClient.java
public List<Box> getBox(String table, String column, int key) throws SQLException { ResultSet rs = stmt.executeQuery("select * from " + table + " where " + column + " = " + key); List<Box> saveBox = new ArrayList<>(); while (rs.next()) { saveBox.add(new Box(rs.getInt("xtl"), rs.getInt("ytl"), rs.getInt("xbr"), rs.getInt("ybr"), rs.getInt("frame"), rs.getBoolean("occluded"), rs.getBoolean("outside"))); }/*from w w w . j a va 2 s . co m*/ return saveBox; }
From source file:org.koiroha.jyro.workers.crawler.Crawler.java
/** * * @param job/*from w w w .ja v a 2 s. c o m*/ * @return * @throws WorkerException */ @Distribute(name = "crawl", params = { "url", "referer" }) public void crawl(String url, String referer) throws SQLException, JyroException { List<URI> urls = retrieveLink(url); WorkerContext context = getContext(); Connection con = Transaction.getConnection(); con.setAutoCommit(false); PreparedStatement stmt1 = con.prepareStatement( "INSERT INTO jyro_urls(scheme,host,port,path,retrieved_at,created_at) VALUES(?,?,?,?,?,?)"); PreparedStatement stmt = con.prepareStatement( "SELECT EXISTS(SELECT * FROM jyro_urls WHERE scheme=? AND host=? AND port=? AND path=?)"); for (URI uri : urls) { int port = getPort(uri); if (port < 0) { logger.debug(uri + " is not supported"); continue; } stmt.setString(1, uri.getScheme()); stmt.setString(2, uri.getHost()); stmt.setInt(3, port); stmt.setString(4, uri.getPath()); ResultSet rs = stmt.executeQuery(); rs.next(); boolean exists = rs.getBoolean(1); if (!exists) { Timestamp now = new Timestamp(System.currentTimeMillis()); stmt1.setString(1, uri.getScheme()); stmt1.setString(2, uri.getHost()); stmt1.setInt(3, port); stmt1.setString(4, uri.getPath()); stmt1.setTimestamp(5, now); stmt1.setTimestamp(6, now); stmt1.executeUpdate(); con.commit(); context.call("crawl", uri.toString()); } else { logger.info("URL " + uri + " already retrieved"); } } stmt.close(); stmt1.close(); con.commit(); return; }
From source file:at.alladin.rmbt.controlServer.StatusResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();//from w ww .j a v a2s.c om JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; final String clientIpRaw = getIP(); final InetAddress clientAddress = InetAddresses.forString(clientIpRaw); System.out.println(MessageFormat.format(labels.getString("NEW_STATUS_REQ"), clientIpRaw)); double geolat = 0; double geolong = 0; float geoaccuracy = 0; // in m double geoaltitude = 0; float geospeed = 0; // in m/s String telephonyNetworkSimOperator = ""; String telephonyNetworkSimCountry = ""; boolean homeCountry = true; if (entity != null && !entity.isEmpty()) { // try parse the string to a JSON object try { // debug parameters sent request = new JSONObject(entity); System.out.println(request.toString(4)); /* sample request Status request from 46.206.21.94 { "accuracy": 65, "altitude": 233.5172119140625, "client": "RMBT", "device": "iPhone", "language": "de", "lat": 48.19530995813387, "long": 16.29190354953834, "model": "iPhone5,2", "name": "RMBT", "network_type": 2, "os_version": "8.1.2", "plattform": "iOS", "softwareRevision": "next-858-8491858", "softwareVersion": "1.3.7", "softwareVersionCode": "1307", "speed": 0, "telephony_network_sim_country": "at", "telephony_network_sim_operator": "232-01", "telephony_network_sim_operator_name": "A1", "time": 1418241092784, "timezone": "Europe/Vienna", "type": "MOBILE", "uuid": "1cf594f6-0d07-4ff6-acd3-3d78ed9c0274", "version": "0.3" } */ geolat = request.optDouble("lat", 0); geolong = request.optDouble("long", 0); geoaccuracy = (float) request.optDouble("accuracy", 0); geoaltitude = request.optDouble("altitude", 0); geospeed = (float) request.optDouble("speed", 0); telephonyNetworkSimOperator = request.optString("telephony_network_sim_operator", ""); telephonyNetworkSimCountry = request.optString("telephony_network_sim_country", ""); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSON Data " + e.toString()); } } else { errorList.addErrorString("Expected request is missing."); } /* * * wb_a2 = 'AT' (2 digit country code) * ne_50m_admin_0_countries (SRID 900913 Mercator) * lat/long (SRID 4326 WGS84) * * SELECT st_contains(the_geom, ST_transform(ST_GeomFromText('POINT(56.391944 48.218056)',4326),900913)) home_country * FROM ne_50m_admin_0_countries * WHERE wb_a2='AT'; * * * */ try { PreparedStatement st; st = conn.prepareStatement( " SELECT st_contains(the_geom, ST_TRANSFORM(ST_GeomFromText( ? ,4326),900913)) home_country " + " FROM ne_50m_admin_0_countries " + " WHERE wb_a2 = ? "); int i = 1; final String point = "POINT(" + String.valueOf(geolong) + " " + String.valueOf(geolat) + ")"; st.setObject(i++, point); st.setObject(i++, telephonyNetworkSimCountry.toUpperCase()); //debug query System.out.println(st.toString()); final ResultSet rs = st.executeQuery(); if (rs.next()) // result only available if country (wb_a2) is found in ne_50_admmin_0_countries homeCountry = rs.getBoolean("home_country"); } catch (final SQLException e) { errorList.addError("ERROR_DB_GENERAL"); e.printStackTrace(); } try { answer.put("home_country", homeCountry); answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }