List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:com.taobao.tdhs.jdbc.TDHSStatement.java
private void doSelectOrCount(com.taobao.tdhs.client.statement.Statement s, ParseSQL parseSQL, String tableName, String dbName) throws SQLException { Query query = preprocessGet(s, parseSQL, tableName, dbName); List<Entry<String, String>> columns = parseSQL.getColumns(); if (columns == null || columns.isEmpty()) { throw new TDHSSQLException("no columns to select!", parseSQL.getSql()); }//from w w w.j a va 2s . co m String[] field = new String[columns.size()]; String[] alias = new String[columns.size()]; int i = 0; for (Entry<String, String> e : columns) { String f = StringUtil.escapeField(e.getValue()); if (f == null) { throw new TDHSSQLException("error in field[" + e.getValue() + "]", parseSQL.getSql()); } field[i] = f; String a = StringUtil.escapeField(e.getKey()); if (a == null) { throw new TDHSSQLException("error in alias[" + e.getKey() + "]", parseSQL.getSql()); } alias[i++] = a; } if (field.length == 1 && field[0].equalsIgnoreCase("count(*)") && !columns.get(0).getValue().startsWith("`")) { TDHSResponse response = null; try { response = query.count(); } catch (TDHSException e) { throw new SQLException(e); } processResponse(response, alias, false, false); } else { query.select(field); TDHSResponse response = null; try { response = query.get(); } catch (TDHSException e) { throw new SQLException(e); } processResponse(response, alias, false, false); } }
From source file:idgs.jdbc.IdgsClient.java
public void initMetaStore(HiveConf conf) throws SQLException { String storeLoaderClass = IdgsConfVars.getVar(conf, IdgsConfVars.STORE_LOADER_CLASS); try {/* w w w.java 2 s.c o m*/ Class<?> _class = Class.forName(storeLoaderClass); Object inst = _class.newInstance(); if (inst instanceof StoreLoader) { StoreLoader loader = (StoreLoader) inst; loader.init(conf); StoreMetadata.getInstance().initMetadata(conf, loader.loadDataStoreConf()); } else { throw new SQLException("class " + storeLoaderClass + " is not StoreLoader"); } } catch (Exception e) { throw new SQLException(e); } }
From source file:ConnectionPool.java
public Connection getConnection() throws SQLException { if (_draining) { throw new SQLException("ConnectionPool was drained."); }/*from w w w. j a v a 2s . c o m*/ // Try reusing an existing Connection synchronized (_connections) { PoolConnection pc = null; for (int i = 0; i < _connections.size(); i++) { pc = _connections.get(i); if (pc.lease()) { // PoolConnection is available if (!_checkConnections) { return pc; } else { // Check the status of the connection boolean isHealthy = true; try { if (pc.isClosed() && pc.getWarnings() != null) { // If something happend to the connection, we // don't want to use it anymore. isHealthy = false; } } catch (SQLException sqle) { // If we can't even ask for that information, we // certainly don't want to use it anymore. isHealthy = false; } if (isHealthy) { return pc; } else { try { pc.expire(); } catch (SQLException sqle) { // ignore } _connections.remove(i); } } } } } // Create a new Connection Connection con = DriverManager.getConnection(_url, _user, _password); PoolConnection pc = new PoolConnection(con); pc.lease(); // Add it to the pool synchronized (_connections) { _connections.add(pc); if (_cleaner == null) { // Put a new PoolCleaner to work _cleaner = new PoolCleaner(_cleaningInterval); _cleaner.start(); } } return pc; }
From source file:com.cws.esolutions.core.dao.impl.ServiceDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IServiceDataDAO#updateService(java.util.List) *//*ww w . j av a2 s . co m*/ public synchronized boolean updateService(final List<String> data) throws SQLException { final String methodName = IServiceDataDAO.CNAME + "#updateService(final List<String> data) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); for (Object str : data) { DEBUGGER.debug("Value: {}", str); } } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL updateServiceData(?, ?, ?, ?, ?, ?, ?, ?)}"); stmt.setString(1, data.get(0)); // guid stmt.setString(2, data.get(1)); // serviceType stmt.setString(3, data.get(2)); // name stmt.setString(4, data.get(3)); // region stmt.setString(5, data.get(4)); // nwpartition stmt.setString(6, data.get(5)); // status stmt.setString(7, data.get(6)); // servers stmt.setString(8, data.get(7)); // description if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } isComplete = (!(stmt.execute())); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return isComplete; }
From source file:es.tid.fiware.rss.expenditureLimit.server.manager.common.test.FactoryResponseTest.java
/** * /*w ww. jav a2 s .c o m*/ */ @Test public void catchConnectionJDBCJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); JDBCConnectionException exception = new JDBCConnectionException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchConnectionJDBCJson(appProperties, mockUriInfo, exception, "resource", "txId"); Assert.assertTrue(true); }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepository.java
/** * Get all subscriptions saved//from www .ja v a 2 s . c o m * @return subscriptions map * @throws SubscriptionPersistenceException */ public Map<String, Subscription> getAllSubscriptions() throws SubscriptionPersistenceException { Map<String, Subscription> subscriptions = new ConcurrentHashMap<>(); try { List<Subscription> subscriptionList = jdbcTemplate.query( "select id, expirationDate, subscribeContext from t_subscriptions", (ResultSet rs, int rowNum) -> { Subscription subscription = new Subscription(); try { subscription.setSubscriptionId(rs.getString("id")); subscription.setExpirationDate(Instant.parse(rs.getString("expirationDate"))); subscription.setSubscribeContext( mapper.readValue(rs.getString("subscribeContext"), SubscribeContext.class)); } catch (IOException e) { throw new SQLException(e); } return subscription; }); subscriptionList .forEach(subscription -> subscriptions.put(subscription.getSubscriptionId(), subscription)); } catch (DataAccessException e) { throw new SubscriptionPersistenceException(e); } return subscriptions; }
From source file:de.anycook.db.mysql.DBHandler.java
private void connect() throws SQLException { if (dataSource == null) { throw new SQLException("Connection pool has not been initialized"); }//from w ww . ja va2s.c om connection = dataSource.getConnection(); }
From source file:com.senior.g40.service.UserService.java
private long getLatestUserId() throws SQLException { Connection conn = ConnectionBuilder.getConnection(); String sqlCmd = "SELECT MAX(userId) AS latestId FROM `profile`;"; PreparedStatement pstm = conn.prepareStatement(sqlCmd); ResultSet rs = pstm.executeQuery(); if (rs.next()) { long latestId = rs.getLong("latestId"); conn.close();// w w w . ja v a 2 s.c o m return latestId; } else { conn.close(); throw new SQLException("Latest userId is N/A."); } }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java
public Set<String> getSubDSTableList(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { if (connectionFactory instanceof VirtualSQLDataSourceMetaData) return ((VirtualSQLDataSourceMetaData) connectionFactory).getSubDSTableList(catalog, schemaPattern, tableNamePattern, types); throw new SQLException("This method only works JDBC/ JNDI sub data source for virtual data source"); }
From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardAction.java
@Override public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { AddCreditCardForm addCreditCardForm = (AddCreditCardForm) form; String accounting = addCreditCardForm.getAccounting(); if (GenericValidator.isBlankOrNull(accounting)) { // Redirect back to credit-card-manager it no accounting selected return mapping.findForward("credit-card-manager"); }//from w ww .j a v a 2s .co m // Populate the initial details from the selected accounting code or authenticated user Business business = aoConn.getBusinesses().get(AccountingCode.valueOf(accounting)); if (business == null) throw new SQLException("Unable to find Business: " + accounting); BusinessProfile profile = business.getBusinessProfile(); if (profile != null) { addCreditCardForm.setFirstName(getFirstName(profile.getBillingContact(), locale)); addCreditCardForm.setLastName(getLastName(profile.getBillingContact(), locale)); addCreditCardForm.setCompanyName(profile.getName()); addCreditCardForm.setStreetAddress1(profile.getAddress1()); addCreditCardForm.setStreetAddress2(profile.getAddress2()); addCreditCardForm.setCity(profile.getCity()); addCreditCardForm.setState(profile.getState()); addCreditCardForm.setPostalCode(profile.getZIP()); addCreditCardForm.setCountryCode(profile.getCountry().getCode()); } else { BusinessAdministrator thisBA = aoConn.getThisBusinessAdministrator(); addCreditCardForm.setFirstName(getFirstName(thisBA.getName(), locale)); addCreditCardForm.setLastName(getLastName(thisBA.getName(), locale)); addCreditCardForm.setStreetAddress1(thisBA.getAddress1()); addCreditCardForm.setStreetAddress2(thisBA.getAddress2()); addCreditCardForm.setCity(thisBA.getCity()); addCreditCardForm.setState(thisBA.getState()); addCreditCardForm.setPostalCode(thisBA.getZIP()); addCreditCardForm.setCountryCode(thisBA.getCountry() == null ? "" : thisBA.getCountry().getCode()); } initRequestAttributes(request, getServlet().getServletContext()); return mapping.findForward("success"); }