List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:it.larusba.neo4j.jdbc.http.driver.CypherExecutor.java
/** * Commit the current transaction.//from w ww. j a v a2 s . c o m * * @throws SQLException */ public void commit() throws SQLException { if (this.getOpenTransactionId() > 0) { HttpPost request = new HttpPost(currentTransactionUrl + "/commit"); Neo4jResponse response = this.executeHttpRequest(request); if (response.hasErrors()) { throw new SQLException(response.displayErrors()); } this.currentTransactionUrl = this.transactionUrl; } else { throw new SQLException("There is no transaction to commit"); } }
From source file:com.taobao.tddl.jdbc.group.TGroupConnection.java
Connection getBaseConnection(String sql, boolean isRead) throws SQLException { int dataSourceIndex = DBSelector.NOT_EXIST_USER_SPECIFIED_INDEX; if (sql == null) { //Connection dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } else {//from ww w . ja va2 s . co m dataSourceIndex = GroupHintParser.convertHint2Index(sql); if (dataSourceIndex < 0) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } } if (dataSourceIndex != DBSelector.NOT_EXIST_USER_SPECIFIED_INDEX) { if (log.isDebugEnabled()) { log.debug("dataSourceIndex=" + dataSourceIndex); } // if (!isAutoCommit) { if (wBaseDsWrapper != null && !wBaseDsWrapper.isMatchDataSourceIndex(dataSourceIndex)) throw new SQLException("Transaction in another dataSourceIndex: " + dataSourceIndex); } if (isRead) { if (rBaseDsWrapper != null && !rBaseDsWrapper.isMatchDataSourceIndex(dataSourceIndex)) closeReadConnection(); } else { if (wBaseDsWrapper != null && !wBaseDsWrapper.isMatchDataSourceIndex(dataSourceIndex)) closeWriteConnection(); } } // if (isRead && isAutoCommit) { // return wBaseConnection != null && wBaseDsWrapper.hasReadWeight() ? wBaseConnection : rBaseConnection; //rBaseConnectionnull } else { if (wBaseConnection != null) { this.tGroupDataSource.setWriteTarget(wBaseDsWrapper); return wBaseConnection; } else if (rBaseConnection != null && rBaseDsWrapper.hasWriteWeight()) { //null wBaseConnection = rBaseConnection; //wBaseConnection // if (wBaseConnection.getAutoCommit() != isAutoCommit) wBaseConnection.setAutoCommit(isAutoCommit); //wBaseDsKey = rBaseDsKey; wBaseDsWrapper = rBaseDsWrapper; this.tGroupDataSource.setWriteTarget(wBaseDsWrapper); return wBaseConnection; } else { return null; } } }
From source file:com.cws.us.pws.dao.impl.CareersReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.ICareersReferenceDAO#getCareerData(String, String) throws SQLException *//*from w ww. jav a 2 s . c om*/ @Override public List<Object> getCareerData(final String reqId, final String lang) throws SQLException { final String methodName = ICareersReferenceDAO.CNAME + "#getCareerData(final int reqId, final String lang) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", reqId); DEBUGGER.debug("Value: {}", lang); } Connection sqlConn = null; ResultSet resultSet = null; List<Object> results = null; CallableStatement stmt = null; try { sqlConn = this.dataSource.getConnection(); if (DEBUG) { DEBUGGER.debug("Connection: {}", sqlConn); } if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain connection to application datasource"); } stmt = sqlConn.prepareCall("{ CALL getCareerData(?, ?) }"); stmt.setString(1, reqId); stmt.setString(2, lang); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new SQLException("PreparedStatement is null. Cannot execute."); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); results = new ArrayList<Object>(); while (resultSet.next()) { results.add(resultSet.getString(1)); // REQ_ID results.add(resultSet.getDate(2)); // POST_DATE results.add(resultSet.getDate(3)); // UNPOST_DATE results.add(resultSet.getString(4)); // JOB_TITLE results.add(resultSet.getString(5)); // JOB_SHORT_DESC results.add(resultSet.getString(6)); // JOB_DESCRIPTION } if (DEBUG) { DEBUGGER.debug("results: {}", results); } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } if (DEBUG) { DEBUGGER.debug("results: {}", results); } return results; }
From source file:com.cws.us.pws.dao.impl.ProductReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.IProductReferenceDAO#getFeaturedProducts(String) throws SQLException *//*from w w w . j a v a 2 s. c om*/ @Override public List<Object[]> getFeaturedProducts(final String lang) throws SQLException { final String methodName = IProductReferenceDAO.CNAME + "#getFeaturedProducts(final String lang) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", lang); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object[]> results = null; try { sqlConn = this.dataSource.getConnection(); if (DEBUG) { DEBUGGER.debug("Connection: {}", sqlConn); } if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain connection to application datasource"); } stmt = sqlConn.prepareCall("{ CALL getFeaturedProducts(?) }"); stmt.setString(1, lang); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new SQLException("PreparedStatement is null. Cannot execute."); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); results = new ArrayList<Object[]>(); while (resultSet.next()) { Object[] data = new Object[] { resultSet.getString(1), // PRODUCT_ID resultSet.getString(2), // PRODUCT_NAME resultSet.getString(3), // PRODUCT_SHORT_DESC resultSet.getString(4), // PRODUCT_DESC resultSet.getBigDecimal(5), // PRODUCT_PRICE resultSet.getBoolean(6) // IS_FEATURED }; results.add(data); } if (DEBUG) { DEBUGGER.debug("results: {}", results); } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } if (DEBUG) { DEBUGGER.debug("results: {}", results); } return results; }
From source file:jp.primecloud.auto.tool.management.db.SQLExecuter.java
public int getNextid(String sql) throws SQLException, Exception { Connection con = null;/*from w w w . j ava 2 s . c o m*/ Statement stmt = null; ResultSet rs = null; int nextid = 0; log.info("[" + sql + "] ???"); try { con = dbConnector.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { nextid = rs.getInt("nextid"); } log.info("[" + sql + "] ????"); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SQLException(e); } catch (Exception e) { log.error(e.getMessage(), e); throw new Exception(e); } finally { try { dbConnector.closeConnection(con, stmt, rs); } catch (Exception e) { e.printStackTrace(); } } return nextid; }
From source file:de.xirp.db.XConnectionProvider.java
/** * Returns a {@link java.sql.Connection} from the pool. * /*from w ww . j a v a 2s. c om*/ * @throws SQLException * if something went wrong getting a connection. * @see org.hibernate.connection.ConnectionProvider#getConnection() * @see java.sql.Connection */ public Connection getConnection() throws SQLException { if (ds != null) { Connection c = ds.getConnection(); /* * logClass.debug("Active: " + * connectionPool.getNumActive( ) + "\n"); * logClass.debug("Idle: " + connectionPool.getNumIdle( ) + * "\n"); */ return c; } else { throw new SQLException(I18n.getString("XConnectionProvider.exception.datasourceNotAvailable")); //$NON-NLS-1$ } }
From source file:com.adaptris.jdbc.connection.FailoverConnection.java
private void validateConnection(int currentDepth) throws SQLException { if (currentDepth > MAX_DEPTH) { throw new SQLException("Too much recursion, check test-statement for : " + config.getConnectionUrls()); }//from www. j a v a2 s.co m if (sqlConnection == null) { if (!this.createConnection()) { throw new SQLException("Could not create any jdbc connections to :- " + config.getConnectionUrls()); } } try { testConnection(); } catch (SQLException e) { logR.warn("Connection lost to [" + currentIndex + "] " + config.getConnectionUrls().get(currentIndex), e); sqlConnection = null; validateConnection(++currentDepth); } return; }
From source file:com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.java
public Object executeQueryForObject(StatementScope statementScope, Transaction trans, Object parameterObject, Object resultObject) throws SQLException { try {//from w w w . j a v a2 s.co m Object object = null; DefaultRowHandler rowHandler = new DefaultRowHandler(); executeQueryWithCallback(statementScope, trans.getConnection(), parameterObject, resultObject, rowHandler, SqlExecutor.NO_SKIPPED_RESULTS, SqlExecutor.NO_MAXIMUM_RESULTS); List list = rowHandler.getList(); if (list.size() > 1) { throw new SQLException("Error: executeQueryForObject returned too many results."); } else if (list.size() > 0) { object = list.get(0); } return object; } catch (TransactionException e) { throw new NestedSQLException("Error getting Connection from Transaction. Cause: " + e, e); } }
From source file:com.concursive.connect.web.modules.documents.dao.FileFolder.java
/** * Description of the Method/*from w w w . j av a2 s . c o m*/ * * @param db Description of the Parameter * @param folderId Description of the Parameter * @throws SQLException Description of the Exception */ public void queryRecord(Connection db, int folderId) throws SQLException { if (folderId == -1) { throw new SQLException("Invalid folder id"); } StringBuffer sql = new StringBuffer(); sql.append("SELECT * " + "FROM project_folders " + "WHERE folder_id > -1 "); if (folderId > -1) { sql.append("AND folder_id = ? "); } if (linkModuleId > -1) { sql.append("AND link_module_id = ? "); } if (linkItemId > -1) { sql.append("AND link_item_id = ? "); } PreparedStatement pst = db.prepareStatement(sql.toString()); int i = 0; if (folderId > -1) { pst.setInt(++i, folderId); } if (linkModuleId > -1) { pst.setInt(++i, linkModuleId); } if (linkItemId > -1) { pst.setInt(++i, linkItemId); } ResultSet rs = pst.executeQuery(); if (rs.next()) { buildRecord(rs); } rs.close(); pst.close(); if (id == -1) { throw new SQLException("Folder record not found."); } }
From source file:com.opensource.dbhelp.DbHelper.java
/** * ? INSERT?UPDATE DELETE ?//from w ww .j av a2 s .c o m * * @param sql * ?sql? * @param params * ? * @return ? * @throws SQLException * - if there is any problem executing the sql */ public int[] batch(String sql, List<Object[]> params) throws SQLException { debug(sql, "batch sql, count:" + ((params == null) ? -1 : params.size())); QueryRunner run = new QueryRunner(dataSource); if (params == null) { throw new SQLException("Null parameters. If parameters aren't need, pass an empty array."); } Object[][] o = new Object[params.size()][]; for (int i = 0; i < params.size(); i++) { o[i] = params.get(i); } return run.batch(sql, o); }