List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:me.crime.loader.DataBaseLoader.java
@Override public void endElement(String uri, String localName, String name) throws SAXException { if (name.compareTo(XmlTags.ELEMENT) == 0) { saveData(current_, buffer_.toString().trim(), curObject_); buffer_.delete(0, buffer_.length()); } else if (name.compareTo(XmlTags.CLASS) == 0) { if (stack_.empty()) { //( curObject_ instanceof me.crime.database.Crime ) { // Crime cr = Crime.class.cast(curObject_); //}/*ww w.j a v a 2s .co m*/ try { curObject_.save(); } catch (SQLException e) { e.printStackTrace(); } count_++; curObject_ = null; } else { XmlReadable tmp = curObject_; curObject_ = stack_.pop(); try { curObject_.handleObject(tmp); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java
/** * Returns a sample dataset./* ww w. ja v a 2 s . c o m*/ * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long time = calendarEnd.getTimeInMillis(); time = time - (time % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(time); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "??? (DCM-)", "ALL_DCM_SIZE", calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset); getMetrics(connection, "? (JPG-)", "ALL_IMAGE_SIZE", calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } return dataset; }
From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java
private long saveAddress(Connection conn, Address address) { long id = -1; String sql = "insert into t_address(f_country, f_province, f_city, f_street, f_postcode)" + " values(?, ?, ?, ?, ?)"; try {/*w w w .java 2 s . co m*/ PreparedStatement preState = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); preState.setString(1, address.getCountry()); preState.setString(2, address.getProvince()); preState.setString(3, address.getCity()); preState.setString(4, address.getStreet()); preState.setString(5, address.getPostcode()); preState.execute(); id = generateId(preState); if (-1 != id) { address.setId(id); } } catch (SQLException e) { e.printStackTrace(); } return id; }
From source file:com.seajas.search.utilities.logging.SearchLogger.java
/** * Default constructor./*www . ja v a 2 s. co m*/ * * @param name * @param level * @param dataSource * @param loggingDAO */ public SearchLogger(final String name, final String level, final BasicDataSource dataSource, final LoggingDAO loggingDAO) { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); // Create the actual logger Logger logger = (Logger) LoggerFactory.getLogger(name); logger.setLevel(Level.toLevel(level)); logger.setAdditive(true); // Create the logging appender AppenderBase<ILoggingEvent> appender = new AppenderBase<ILoggingEvent>() { @Override protected void append(final ILoggingEvent event) { Connection connection = null; PreparedStatement statement = null; try { connection = dataSource.getConnection(); statement = connection.prepareStatement(JDBC_INSERT); statement.setString(1, event.getLevel().toString()); statement.setString(2, event.getFormattedMessage()); statement.setDate(3, new Date(event.getTimeStamp())); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) statement.close(); if (connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } }; appender.setContext(loggerContext); appender.start(); // Make this the definitive logger logger.addAppender(appender); this.logger = logger; }
From source file:io.apiman.gateway.engine.jdbc.PollCachingJdbcRegistry.java
/** * Checks the ES store to see if the 'dataVersion' entry has been updated with a newer * version #. If it has, then we need to invalidate our cache. *///w ww .j av a 2 s . c o m protected void checkCacheVersion() { // Be very aggressive in invalidating the cache. boolean invalidate = true; QueryRunner run = new QueryRunner(ds); try { long latestVersion = run.query("SELECT version FROM gw_dataversion", Handlers.LONG_HANDLER); //$NON-NLS-1$ if (latestVersion > -1 && dataVersion > -1 && latestVersion == dataVersion) { invalidate = false; } else { dataVersion = latestVersion; } } catch (SQLException e) { // TODO need to use the gateway logger to log this! e.printStackTrace(); } if (invalidate) { invalidateCache(); } }
From source file:org.projecthdata.weight.WeightTrackerActivity.java
private void onClearDataMenuItem() { try {/* w ww . j a v a 2s . c o m*/ Dao<WeightReading, Integer> dao = getDatabaseHelper().getWeightDao(); dao.delete(dao.deleteBuilder().prepare()); weightListFragment.onResume(); chartFragment.refreshChart(); } catch (SQLException e) { e.printStackTrace(); } }
From source file:edu.ku.brc.specify.utilapps.morphbank.BaseFileNameParser.java
@Override public Integer getRecordId(final String baseName) { Integer recId = null;//from w w w .j av a 2s. c om if (pStmt == null) { String whereStr = QueryAdjusterForDomain.getInstance().getSpecialColumns(this.tblInfo, false); String sql = String.format("SELECT %s FROM %s WHERE BINARY %s=? %s ", tblInfo.getIdColumnName(), tblInfo.getName(), StringUtils.capitalize(this.fieldName), whereStr != null ? (" AND " + whereStr) : ""); try { System.out.println(sql); pStmt = DBConnection.getInstance().getConnection().prepareStatement(sql); } catch (SQLException e) { e.printStackTrace(); return null; } } if (pStmt != null) { try { //String baseName = FilenameUtils.getBaseName(fileName); String fieldNameValue = fldInfo.getFormatter() == null ? baseName : getTrimmedFileName(baseName); pStmt.setString(1, fieldNameValue); ResultSet rs = pStmt.executeQuery(); if (rs.next()) { recId = rs.getInt(1); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } } return recId; }
From source file:com.drevelopment.couponcodes.bukkit.coupon.BukkitCouponHandler.java
@Override public void updateCouponTime(Coupon coupon) { try {//from w w w . j a v a 2 s . c om databaseHandler.query("UPDATE couponcodes SET timeuse='" + coupon.getTime() + "' WHERE name='" + coupon.getName() + "'"); } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.thinkbiganalytics.server.upgrade.KyloUpgradeDatabaseVersionChecker.java
/** * Query the Database for the Kylo Version * * @return the KyloVersion from the database, or null if not found or if an error occurs *//*ww w.j a v a2 s . c om*/ public KyloVersion getDatabaseVersion() { KyloVersion version = null; Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { String user = environmentProperties.getPropertyValueAsString("spring.datasource.username"); String password = environmentProperties.getPropertyValueAsString("spring.datasource.password"); password = encryptionService.isEncrypted(password) ? encryptionService.decrypt(password) : password; String uri = environmentProperties.getPropertyValueAsString("spring.datasource.url"); String driverClassName = environmentProperties .getPropertyValueAsString("spring.datasource.driverClassName"); boolean testOnBorrow = BooleanUtils .toBoolean(environmentProperties.getPropertyValueAsString("spring.datasource.testOnBorrow")); String validationQuery = environmentProperties .getPropertyValueAsString("spring.datasource.validationQuery"); PoolingDataSourceService.DataSourceProperties dataSourceProperties = new PoolingDataSourceService.DataSourceProperties( user, password, uri, driverClassName, testOnBorrow, validationQuery); DataSource dataSource = PoolingDataSourceService.getDataSource(dataSourceProperties); connection = dataSource.getConnection(); String query = "SELECT * FROM KYLO_VERSION ORDER BY MAJOR_VERSION DESC, MINOR_VERSION DESC, POINT_VERSION DESC, TAG DESC"; statement = connection.createStatement(); ResultSet rs = statement.executeQuery(query); if (rs.next()) { String majorVersion = rs.getString("MAJOR_VERSION"); String minorVersion = rs.getString("MINOR_VERSION"); String pointVersion = rs.getString("POINT_VERSION"); String tag = rs.getString("TAG"); version = new KyloVersionUtil.Version(majorVersion, minorVersion, pointVersion, tag); } } catch (SQLException e) { // this is ok.. If an error happens assume the upgrade is needed. The method will return a null value if errors occur and the upgrade app will start. e.printStackTrace(); } finally { JdbcUtils.closeStatement(statement); JdbcUtils.closeResultSet(resultSet); JdbcUtils.closeConnection(connection); } return version; }
From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java
@Override public boolean saveAll(List<User> entities) { if (null != entities) { Connection conn = getConnection(); try {/*from w ww.j a v a2 s. c o m*/ conn.setAutoCommit(false); for (User user : entities) { save(user); } conn.commit(); } catch (SQLException e) { e.printStackTrace(); try { conn.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } } } return super.saveAll(entities); }