List of usage examples for java.sql ResultSet getInt
int getInt(String columnLabel) throws SQLException;
ResultSet
object as an int
in the Java programming language. 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 www .ja va 2 s . co m 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:local.Statistics.LessSellCars.java
/** * @param args the command line arguments *//*from w w w. j a v a 2 s .co m*/ public static void carrosMenosVendidos() { Graficas_DAO gr = new Graficas_DAO(); ResultSet rs = gr.getgraficaautomas(); try { String nameAuto; int quantitySales; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MENOS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Autos menos vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(LessSellCars.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:local.Statistics.LessSellRepuesto.java
/** * @param args the command line arguments *///from w w w. ja v a2 s . c o m public static void repuestosMenosVendidos() { Graficas_DAO gr = new Graficas_DAO(); //obtencion de datos ResultSet rs = gr.getgraficarepuestomen(); try { String nameAuto; int quantitySales; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS REPUESTO MENOS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Repuestos menos vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(LessSellRepuesto.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.sap.dirigible.repository.db.dao.DBMapper.java
/** * ResultSet current row to DB Repository transformation * // w w w. j ava 2s. c om * @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.CachedRowSetSample.java
public static void viewTable(Connection con) throws SQLException { Statement stmt = null;/*from www.ja v a2s. co m*/ String query = "select * from MERCH_INVENTORY"; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { System.out.println("Found item " + rs.getInt("ITEM_ID") + ": " + rs.getString("ITEM_NAME") + " (" + rs.getInt("QUAN") + ")"); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:de.sqlcoach.db.jdbc.DBAppUser.java
/** * Sets the model.//from w w w. j a v a 2 s.c o m * * @param resultset * the resultset * @param model * the model * * @throws SQLException * the SQL exception */ private static void setModel(ResultSet resultset, AppUser model) throws SQLException { model.setId(resultset.getInt("id")); model.setNickname(resultset.getString("nickname")); model.setPassword(resultset.getString("password")); model.setTitle(resultset.getString("title")); model.setFirstname(resultset.getString("firstname")); model.setLastname(resultset.getString("lastname")); model.setEmail(resultset.getString("email")); model.setRole(resultset.getString("role")); model.setDatecreate(resultset.getTimestamp("datecreate")); model.setDatelastmod(resultset.getTimestamp("datelastmod")); }
From source file:com.nokia.helium.metadata.DerbyFactoryManagerCreator.java
/** * Checks the database integrity.//w ww . ja v a2 s. co m * @param urlPath - database path to be connected to. * @return boolean - true if db is valid false otherwise. */ private static boolean checkDatabaseIntegrity(File database) throws MetadataException { boolean result = false; Connection connection = null; try { connection = DriverManager.getConnection("jdbc:derby:" + database); if (connection != null) { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("select version from version"); int version = -1; if (rs.next()) { version = rs.getInt(1); } rs.close(); stmt.close(); connection.close(); connection = null; result = version == Version.DB_VERSION; } } catch (SQLException ex) { try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } return false; } finally { try { if (connection != null) { connection.close(); } } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } connection = null; if (!result) { try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } } } //shutdown unloads the driver, driver need to be loaded again. return result; }
From source file:local.Statistics.MostSellCars.java
/** * @param args the command line arguments *//* w ww. ja v a2 s . co m*/ public static void carrosMasVendidos() { Graficas_DAO gr = new Graficas_DAO(); //obtencion de datos ResultSet rs = gr.getgraficaautomas(); try { String nameAuto; int quantitySales; Object[] fila = new Object[3]; DefaultPieDataset data = new DefaultPieDataset(); while (rs.next()) { nameAuto = rs.getString(3); quantitySales = rs.getInt(1); data.setValue(nameAuto, quantitySales); } JFreeChart chart = ChartFactory.createPieChart("GRAFICAS AUTOS MAS VENDIDOS", data, true, true, false); ChartFrame frame = new ChartFrame("Autos mas vendidos", chart); frame.pack(); frame.setVisible(true); rs.close(); gr.close(); } catch (SQLException ex) { Logger.getLogger(MostSellCars.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java
static public void dispose(final Connection conn, final Integer assetId, final IDisposal disposal) throws SQLException, DispatchException { final PreparedStatement redo = conn .prepareStatement("INSERT INTO fa_transaction_redo (fa_asset_id, command) VALUES(?,?);"); try {/*from w w w .ja v a 2 s .co m*/ redo.setInt(1, assetId); // backup transaction after disposal if any if (log.isDebugEnabled()) log.debug("backing up transactions after disposal date"); // charge monthly depreciation in disposal month if disposal is after 15 final Calendar dt = Util.dateToCalendar(disposal.getDate()); if (dt.get(GregorianCalendar.DAY_OF_MONTH) >= dt.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) / 2) dt.add(GregorianCalendar.MONTH, 1); dt.set(GregorianCalendar.DAY_OF_MONTH, 1); final Date from = Util.calendarToSqlDate(dt); // get list of transactions to backup before we delete them final IntegerSet transIds = new IntegerSet(); final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT t.*" + " FROM fa_transaction AS t INNER JOIN period_end AS p ON t.period_end_id=p.id" + " WHERE t.fa_asset_id=? AND p.end_date>?;", assetId, from); try { final ResultSet rs = stmt.executeQuery(); try { while (rs.next()) { transIds.add(rs.getInt("id")); final String command = MessageFormat.format("INSERT INTO fa_transaction" + " (id,fa_asset_id,period_end_id,amount,class,type,depreciation_period)" + " VALUES({0,number,0},{1,number,0},{2,number,0},{3,number,0},''{4}'',''{5}'',{6,number,0});", rs.getInt("id"), rs.getInt("fa_asset_id"), rs.getInt("period_end_id"), rs.getInt("amount"), rs.getString("class"), rs.getString("type"), Database.getInteger(rs, "depreciation_period")); if (log.isTraceEnabled()) log.trace("redo = " + command); redo.setString(2, command); redo.addBatch(); } } finally { rs.close(); } } finally { stmt.close(); } // remove any transaction after disposal date if (log.isDebugEnabled()) log.debug("removing transactions after disposal date"); Database.executeUpdate(conn, "DELETE FROM fa_transaction WHERE id IN (?);", transIds); // add disposal transactions if (log.isDebugEnabled()) log.debug("adding transactions for disposal"); final TransactionList transactions = new TransactionList(assetId); // closing cost transactions.add(new Transaction(TransactionClasses.COST, TransactionTypes.CLOSING, disposal.getDate(), -1 * getAssetCostBeforeDisposal(conn, assetId))); // closing accumulated depreciation transactions.add(new Transaction(TransactionClasses.DEP, TransactionTypes.CLOSING, disposal.getDate(), -1 * getAssetDepreciationBeforeDisposal(conn, assetId))); for (Integer newTransId : transactions.save(conn, true)) { redo.setString(2, MessageFormat.format("DELETE FROM fa_transaction WHERE id={0,number,0};", newTransId)); redo.addBatch(); } if (!Database.isBatchCompleted(redo.executeBatch())) throw new InternalErrorException("failed to save disposal transactions"); } finally { redo.close(); } }
From source file:dsd.dao.ParsedInputFilesDAO.java
public static boolean IsAlreadyParsed(String fileName) { boolean isAlreadyParsed = false; try {//from w ww.j ava 2 s . c o m Connection con = DAOProvider.getDataSource().getConnection(); try { Object[] parameters = new Object[1]; parameters[0] = fileName; ResultSet results = DAOProvider.SelectTableSecure(tableName, " count(*) ", " name = ? ", "", con, parameters); while (results.next()) { isAlreadyParsed = results.getInt(1) == 1 ? true : false; } } catch (Exception exc) { exc.printStackTrace(); } con.close(); } catch (Exception exc) { exc.printStackTrace(); } return isAlreadyParsed; }