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:RSMetaData.java
public static void getData(ResultSet rs, int type, int colIdx) throws SQLException { switch (type) { case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: System.out.println(rs.getString(colIdx)); break;/*from w ww .j a v a 2 s . c om*/ case java.sql.Types.INTEGER: int i = rs.getInt(colIdx); System.out.println(i); break; case java.sql.Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIdx); System.out.println(bd.toString()); break; case java.sql.Types.TIMESTAMP: case java.sql.Types.DATE: java.sql.Date d = rs.getDate(colIdx); System.out.println(d.toString()); break; } }
From source file:PieChartCreate.PieChart_AWT.java
private static PieDataset createDataset(ResultSet resultSet) { try {//from w w w.j a v a 2s .co m DefaultPieDataset dataset = new DefaultPieDataset(); while (resultSet.next()) { dataset.setValue(resultSet.getString(1), new Double(resultSet.getString(2))); } return dataset; } catch (SQLException ex) { Logger.getLogger(PieChart_AWT.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:Main.java
public static int storedProcWithResultSet() throws Exception { Connection conn = null;/*w ww . j ava 2s .c o m*/ CallableStatement cs = conn.prepareCall("{? = call proc (?,?,?,?,?,?,?)}"); // register input parameters cs.setString(2, ""); cs.setString(3, ""); cs.setString(4, "123"); // regsiter ouput parameters cs.registerOutParameter(5, java.sql.Types.CHAR); cs.registerOutParameter(6, java.sql.Types.CHAR); cs.registerOutParameter(7, java.sql.Types.CHAR); // Procedure execution ResultSet rs = cs.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int nbCol = rsmd.getColumnCount(); while (rs.next()) { for (int i = 1; i <= nbCol; i++) { System.out.println(rs.getString(i)); System.out.println(rs.getString(i)); } } // OUTPUT parameters System.out.println("return code of Stored procedure = : " + cs.getInt(1)); for (int i = 5; i <= 7; i++) System.out.println("parameter " + i + " : " + cs.getString(i)); return cs.getInt(1); }
From source file:com.sap.dirigible.repository.db.dao.DBMapper.java
/** * ResultSet current row to DB Repository transformation * /*from w w w.java 2 s . c o m*/ * @param repository * @param resultSet * @return * @throws SQLException * @throws DBBaseException */ static DBObject dbToObject(DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException { String name = resultSet.getString(FILE_NAME); String path = resultSet.getString(FILE_PATH); int type = resultSet.getInt(FILE_TYPE); String content = resultSet.getString(FILE_CONTENT_TYPE); String createdBy = resultSet.getString(FILE_CREATED_BY); Date createdAt = new Date(resultSet.getTimestamp(FILE_CREATED_AT).getTime()); String modifiedBy = resultSet.getString(FILE_MODIFIED_BY); Date modifiedAt = new Date(resultSet.getTimestamp(FILE_MODIFIED_AT).getTime()); DBObject dbObject = null; if (type == OBJECT_TYPE_FOLDER) { dbObject = new DBFolder(repository); } else if (type == OBJECT_TYPE_DOCUMENT) { dbObject = new DBFile(repository, false, content); } else if (type == OBJECT_TYPE_BINARY) { dbObject = new DBFile(repository, true, content); } else { throw new DBBaseException(Messages.getString("DBMapper.THE_OBJECT_IS_UNKNOWN")); //$NON-NLS-1$ } dbObject.setName(name); dbObject.setPath(path); dbObject.setCreatedBy(createdBy); dbObject.setCreatedAt(new java.util.Date(createdAt.getTime())); dbObject.setModifiedBy(modifiedBy); dbObject.setModifiedAt(new java.util.Date(modifiedAt.getTime())); return dbObject; }
From source file:com.oracle.tutorial.jdbc.FilteredRowSetSample.java
public static void viewTable(Connection con) throws SQLException { Statement stmt = null;//from w ww . j a v a 2s .c om String query = "select * from COFFEE_HOUSES"; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { System.out.println(rs.getInt("STORE_ID") + ", " + rs.getString("CITY") + ", " + rs.getInt("COFFEE") + ", " + rs.getInt("MERCH") + ", " + rs.getInt("TOTAL")); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:com.app.dao.CategoryDAO.java
private static Category _createCategoryFromResultSet(ResultSet resultSet) throws SQLException { Category category = new Category(); category.setCategoryId(resultSet.getString("categoryId")); category.setCategoryName(resultSet.getString("categoryName")); category.setCategoryParentId(resultSet.getString("categoryParentId")); category.setCategoryLevel(resultSet.getInt("categoryLevel")); return category; }
From source file:com.sap.dirigible.repository.db.dao.DBMapper.java
public static DBFileVersion dbToFileVersion(Connection connection, DBRepository repository, ResultSet resultSet) throws SQLException, DBBaseException, IOException { String path = resultSet.getString("FV_FILE_PATH"); //$NON-NLS-1$ int version = resultSet.getInt("FV_VERSION"); //$NON-NLS-1$ byte[] bytes = dbToDataBinary(connection, resultSet, "FV_CONTENT"); //$NON-NLS-1$ int type = resultSet.getInt("FV_TYPE"); //$NON-NLS-1$ String content = resultSet.getString("FV_CONTENT_TYPE"); //$NON-NLS-1$ String createdBy = resultSet.getString("FV_CREATED_BY"); //$NON-NLS-1$ Date createdAt = new Date(resultSet.getTimestamp("FV_CREATED_AT") //$NON-NLS-1$ .getTime());//from ww w .j av a2 s.c om DBFileVersion dbFileVersion = new DBFileVersion(repository, (type == OBJECT_TYPE_BINARY), content, version, bytes); dbFileVersion.setPath(path); dbFileVersion.setCreatedBy(createdBy); dbFileVersion.setCreatedAt(createdAt); return dbFileVersion; }
From source file:br.ufmt.ic.pawii.util.Estados.java
public static String getEstados(String estado, String nome, String email) { try {/* w w w .j av a 2 s . c o m*/ String strCidades; Statement stm; Connection con = ConnBD.getConnection(); if (con == null) { throw new SQLException("Erro conectando"); } stm = con.createStatement(); String sql = "SELECT codigo,municipio FROM municipios" + " WHERE uf='" + estado + "' ORDER BY municipio ASC"; ResultSet rs = stm.executeQuery(sql); JSONArray cidades = new JSONArray(); while (rs.next()) { String codigo = rs.getString(1); String cidade = rs.getString(2); JSONObject jsonCidade = new JSONObject(); jsonCidade.put("codigo", codigo); jsonCidade.put("nome", cidade); cidades.put(jsonCidade); } JSONObject jsonRetorno = new JSONObject(); jsonRetorno.put("cidades", cidades); jsonRetorno.put("seuNome", nome); jsonRetorno.put("seuEmail", email); strCidades = jsonRetorno.toString(); return strCidades; } catch (SQLException ex) { System.out.println("Error: " + ex.getMessage()); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } return null; }
From source file:de.dakror.virtualhub.server.DBManager.java
public static JSONObject tagdata(String catalog) { JSONObject o = new JSONObject(); try {/*from w w w. jav a 2s . c o m*/ ResultSet rs = connection.createStatement().executeQuery("SELECT * FROM TAGS"); while (rs.next()) { o.put(rs.getString(1), rs.getString(3).split(", ")); } } catch (Exception e) { e.printStackTrace(); } return o; }
From source file:org.jw.service.factory.StatisticsChartFactory.java
public static CategoryDataset createCategoryDataset(Connection conn, String query) throws SQLException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Statement statement = conn.createStatement(); ResultSet resultSet = statement.executeQuery(query); while (resultSet.next()) { Double value = resultSet.getDouble("value"); String series = resultSet.getString("series"); String category = resultSet.getString("category"); dataset.addValue(value, series, category); }/*from ww w . j a v a2 s . c om*/ return dataset; }