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:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java
public static void relatoriosVendas() throws SQLException, ClassNotFoundException { String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM FILIAL FL " + "INNER JOIN FUNCIONARIO FUNC ON FUNC.ID_FILIAL = FL.ID_FILIAL " + "INNER JOIN ALUGUEL AL ON AL.ID_FUNCIONARIO = FUNC.ID_FUNCIONARIO " + "GROUP BY FL.NOME_FILIAL"; Connection conn = Conexoes.obterConexao(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); DefaultCategoryDataset ds = new DefaultCategoryDataset(); while (rs.next()) { ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL")); }// www .j ava 2 s . co m JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Aluguis", "Filiais", "Separadas por filiais", ds, PlotOrientation.VERTICAL, true, true, false); try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\vendas.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) { try (OutputStream arquivo = new FileOutputStream( "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } }
From source file:com.acme.spring.jdbc.JdbcTestHelper.java
/** * <p>Retrieves all the stocks from database, using passed {@link JdbcTemplate}.</p> * * @param jdbcTemplate the jdbc template to use * * @return list of stocks retrieved from database *///from www . ja v a 2 s.c o m public static List<Stock> retrieveAllStocks(JdbcTemplate jdbcTemplate) { return jdbcTemplate.query("select id, name, symbol, value, date from Stock order by name", new RowMapper<Stock>() { public Stock mapRow(ResultSet rs, int rowNum) throws SQLException { int index = 1; Stock result = new Stock(); result.setId(rs.getLong(index++)); result.setName(rs.getString(index++)); result.setSymbol(rs.getString(index++)); result.setValue(rs.getBigDecimal(index++)); result.setDate(rs.getDate(index++)); return result; } }); }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static Optional<Event> load(Connection connection, long id) throws SQLException, IOException { try (PreparedStatement statement = connection .prepareStatement("SELECT \"data\",\"removed\" FROM \"events\" WHERE \"id\"=?")) { statement.setLong(1, id);/*from w w w . j a v a 2s. c om*/ ResultSet result = statement.executeQuery(); if (result.next()) { String evString = result.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = id; event.removed = result.getBoolean("removed"); return Optional.of(event); } else { return Optional.empty(); } } }
From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java
public static void relatoriosDisponibilidade() throws SQLException, ClassNotFoundException { String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM CARRO CA " + "INNER JOIN FILIAL FL ON FL.ID_FILIAL = CA.ID_FILIAL " + "WHERE CA.DISPONIBILIDADE_CARRO = '1' " + "GROUP BY FL.NOME_FILIAL"; Connection conn = Conexoes.obterConexao(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); DefaultCategoryDataset ds = new DefaultCategoryDataset(); while (rs.next()) { ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL")); }/*w w w. j a va 2s. c o m*/ /*File fg = new File("C:\\Users\\bruno.lopes.KRONMED\\Documents\\NetBeansProjects\\LoCarSys\\src\\main\\webapp\\ImagensLoCarSys\\disponibilidade.png"); fg.delete();*/ JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Disponibilidade", "Filiais", "Separados por filiais", ds, PlotOrientation.VERTICAL, true, true, false); //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\disponibilidade.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { try (OutputStream arquivo = new FileOutputStream( "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } }
From source file:com.github.dactiv.common.unit.Fixtures.java
/** * ,excludeTables.disable.//from w ww . j ava2 s . co m * @throws SQLException */ public static void deleteAllTable(DataSource h2DataSource, String... excludeTables) throws SQLException { List<String> tableNames = new ArrayList<String>(); try { ResultSet rs = h2DataSource.getConnection().getMetaData().getTables(null, null, null, new String[] { "TABLE" }); while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); if (Arrays.binarySearch(excludeTables, tableName) < 0) { tableNames.add(tableName); } } deleteTable(h2DataSource, tableNames.toArray(new String[tableNames.size()])); } catch (SQLException e) { throw e; } }
From source file:com.seventh_root.ld33.common.player.Player.java
public static Player getByName(Connection databaseConnection, String playerName) throws SQLException { if (playersByName.containsKey(playerName)) return playersByName.get(playerName); if (databaseConnection != null) { PreparedStatement statement = databaseConnection.prepareStatement( "SELECT uuid, name, password_hash, password_salt, resources FROM player WHERE name = ? LIMIT 1"); statement.setString(1, playerName); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { return new Player(databaseConnection, UUID.fromString(resultSet.getString("uuid")), resultSet.getString("name"), resultSet.getString("password_hash"), resultSet.getString("password_salt"), resultSet.getInt("resources")); }// w ww . java 2 s . co m } return null; }
From source file:massbank.extend.ChemicalFormulaUtils.java
/** * CIqXg//from w w w .j ava 2 s.com */ public static List<String[]> getIonMassList() throws IOException { List<String[]> massList = new ArrayList(); try { Class.forName("com.mysql.jdbc.Driver"); String conUrl = "jdbc:mysql://localhost/FORMULA_STRUCTURE_RELATION"; Connection con = DriverManager.getConnection(conUrl, "bird", "bird2006"); Statement stmt = con.createStatement(); String sql = "SELECT FORMULA, MASS FROM ION_MASS order by MASS"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String formula = rs.getString("FORMULA"); String mass = rs.getString("MASS"); massList.add(new String[] { formula, mass }); } rs.close(); stmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } return massList; }
From source file:com.bluepandora.therap.donatelife.gcmservice.FindDonator.java
/** * * @param mobileNumber/*w w w. j a v a 2s . c om*/ * @return This function will return the List of GCM ID of this mobile * Number */ public static List findDonatorGCMId(String mobileNumber, DatabaseService dbService) { String query = GetQuery.getGcmIdOfDonatorQuery(mobileNumber); Debug.debugLog("FIND DONATOR: ", query); ResultSet result = dbService.getResultSet(query); List donatorList = new ArrayList<String>(); Debug.debugLog("REQUESTER GCM ID FINDING"); try { while (result.next()) { mobileNumber = result.getString("mobile_number"); String gcmId = result.getString("gcm_id"); if (gcmId.length() > VALID_GCM_SIZE_GREATER) { Debug.debugLog("Mobile: ", mobileNumber, "GCM Id: ", gcmId); donatorList.add(gcmId); } } } catch (SQLException error) { Debug.debugLog("FINDING DONATOR'S GCM SQL EXCEPTION!"); } return donatorList; }
From source file:com.seventh_root.ld33.common.player.Player.java
public static Player getByUUID(Connection databaseConnection, UUID uuid) throws SQLException { if (playersByUUID.containsKey(uuid.toString())) return playersByUUID.get(uuid.toString()); if (databaseConnection != null) { PreparedStatement statement = databaseConnection.prepareStatement( "SELECT uuid, name, password_hash, password_salt, resources FROM player WHERE uuid = ? LIMIT 1"); statement.setString(1, uuid.toString()); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { Player player = new Player(databaseConnection, UUID.fromString(resultSet.getString("uuid")), resultSet.getString("name"), resultSet.getString("password_hash"), resultSet.getString("password_salt"), resultSet.getInt("resources")); cachePlayer(player);//from w w w .java2 s . c om return player; } } return null; }
From source file:at.becast.youploader.account.Account.java
public static Account read(String name) throws IOException { PreparedStatement stmt;/* w ww . j a v a 2s .co m*/ try { stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `name`=? LIMIT 1"); stmt.setString(1, name); ResultSet rs = stmt.executeQuery(); ObjectMapper mapper = new ObjectMapper(); List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() { }); int id = rs.getInt("id"); String token = rs.getString("refresh_token"); stmt.close(); rs.close(); return new Account(id, name, token, c); } catch (SQLException e) { LOG.error("Account read error!", e); return null; } }