List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:com.cws.us.pws.dao.impl.CareersReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.ICareersReferenceDAO#getCareerList(String) throws SQLException *//*w w w . j a va 2 s .c om*/ @Override public List<Object[]> getCareerList(final String lang) throws SQLException { final String methodName = ICareersReferenceDAO.CNAME + "#getCareerList(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 getCareersList(?) }"); 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), // REQ_ID resultSet.getString(2), // POST_DATE resultSet.getString(3), // UNPOST_DATE resultSet.getString(4), // JOB_TITLE resultSet.getBigDecimal(5), // JOB_SHORT_DESC resultSet.getString(6), // JOB_DESCRIPTION }; 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:es.upm.fiware.rss.expenditureLimit.server.exceptionhandles.test.ExpenditureLimitExceptionMapperTest.java
public void toResponse() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go")); ReflectionTestUtils.setField(mapper, "ui", mockUriInfo); RSSException e = new RSSException("RssException"); Response response = mapper.toResponse(e); Assert.assertTrue(true);// w ww . j a va 2 s . com GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason")); response = mapper.toResponse(ex); Assert.assertTrue(true); JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason")); response = mapper.toResponse(ex1); Assert.assertTrue(true); NotFoundException ex2 = new NotFoundException(); response = mapper.toResponse(ex2); Assert.assertTrue(true); Exception ex3 = new Exception("RssException"); response = mapper.toResponse(ex3); Assert.assertTrue(true); Exception ex4 = new Exception("RssException", ex); response = mapper.toResponse(ex4); Assert.assertTrue(true); Exception ex5 = new Exception("RssException", ex1); response = mapper.toResponse(ex5); Assert.assertTrue(true); }
From source file:com.flipkart.flux.type.SetJsonType.java
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (value == null) { return new HashSet<String>(); }// ww w. jav a 2s. co m try { return deSerialize(value); } catch (IOException e) { throw new SQLException("Cannot deserialize json string " + value + ". Exception " + e.getMessage()); } }
From source file:commondb.mock.MockResultSet.java
public void loadCSV(Readable in) throws SQLException { final Scanner sc = new Scanner(in); if (!sc.hasNextLine()) { throw new SQLException("empty data source"); }/*ww w . j a v a 2s. c o m*/ // load column headers String line = sc.nextLine(); int index = 1; for (String column : splitter.split(line)) { columnMap.put(column, index); index++; } // load data while (sc.hasNextLine()) { line = sc.nextLine(); String[] row = splitter.split(line); rowset.add(row); } sc.close(); }
From source file:fr.acxio.tools.agia.item.database.ExpressionsPreparedStatementSetter.java
@Override public synchronized void setValues(PreparedStatement sPs) throws SQLException { try {//ww w.ja va 2 s. c o m String aResolvedValue; for (int i = 0; i < lookupFieldsExpressions.length; i++) { aResolvedValue = getExpressionResolver().evaluate(lookupFieldsExpressions[i], getEvaluationContext(), String.class); StatementCreatorUtils.setParameterValue(sPs, i + 1, SqlTypeValue.TYPE_UNKNOWN, aResolvedValue); } } catch (Exception e) { throw new SQLException(new PreparedStatementCreationException(e)); } }
From source file:com.wso2telco.dbutils.DbUtils.java
/** * IMPORTANT : This method must be deprecated. going forward use * "getDbConnection(DataSourceNames dataSourceName)" method Gets the axiata * db connection./* ww w. j av a 2 s . c o m*/ * * @return the axiata db connection * @throws SQLException * the SQL exception * @throws AxataDBUtilException * the axata db util exception */ @Deprecated public static Connection getAxiataDBConnection() throws SQLException, AxataDBUtilException { initializeDatasources(); if (axiataDatasource != null) { return axiataDatasource.getConnection(); } throw new SQLException("Axiata Datasource not initialized properly"); }
From source file:it.larusba.neo4j.jdbc.http.driver.Neo4jStatement.java
/** * Default constructor.//from w ww . j a v a 2 s. c o m * * @param statement Cypher query * @param parameters List of named params for the cypher query * @param includeStats Do we need to include stats */ public Neo4jStatement(String statement, Map<String, Object> parameters, Boolean includeStats) throws SQLException { if (statement != null && !statement.equals("")) { this.statement = statement; } else { throw new SQLException("Creating a NULL query"); } if (parameters != null) { this.parameters = parameters; } else { this.parameters = new HashMap(); } if (includeStats != null) { this.includeStats = includeStats; } else { this.includeStats = Boolean.FALSE; } }
From source file:mondrian.xmla.impl.Olap4jXmlaServlet.java
/** * Unwraps a given interface from a given connection. * * @param connection Connection object//from w w w. j av a 2 s . c o m * @param clazz Interface to unwrap * @param <T> Type of interface * @return Unwrapped object; never null * @throws java.sql.SQLException if cannot convert */ private static <T> T unwrap(Connection connection, Class<T> clazz) throws SQLException { // Invoke Wrapper.unwrap(). Works for JDK 1.6 and later, but we use // reflection so that it compiles on JDK 1.5. try { final Class<?> wrapperClass = Class.forName("java.sql.Wrapper"); if (wrapperClass.isInstance(connection)) { Method unwrapMethod = wrapperClass.getMethod("unwrap"); return clazz.cast(unwrapMethod.invoke(connection, clazz)); } } catch (ClassNotFoundException e) { // ignore } catch (NoSuchMethodException e) { // ignore } catch (InvocationTargetException e) { // ignore } catch (IllegalAccessException e) { // ignore } if (connection instanceof OlapWrapper) { OlapWrapper olapWrapper = (OlapWrapper) connection; return olapWrapper.unwrap(clazz); } throw new SQLException("not an instance"); }
From source file:com.cws.us.pws.dao.impl.ProductReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.IProductReferenceDAO#getProductList(String) throws SQLException *///from w ww . ja va 2 s .c o m @Override public List<Object[]> getProductList(final String lang) throws SQLException { final String methodName = IProductReferenceDAO.CNAME + "#getProductList(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 getProductList(?) }"); 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:com.cws.esolutions.security.dao.userauth.impl.SQLAuthenticator.java
/** * @see com.cws.esolutions.security.dao.userauth.interfaces.Authenticator#performLogon(java.lang.String, java.lang.String) *//*from w w w.ja va2 s .c om*/ public synchronized List<Object> performLogon(final String username, final String password) throws AuthenticatorException { final String methodName = SQLAuthenticator.CNAME + "#performLogon(final String user, final String password) throws AuthenticatorException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("String: {}", username); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object> userAccount = null; try { sqlConn = SQLAuthenticator.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL performAuthentication(?, ?)}"); stmt.setString(1, username); // username stmt.setString(2, password); // password if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new AuthenticatorException("No user was found for the provided user information"); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.first(); userAccount = new ArrayList<Object>(); for (String returningAttribute : userAttributes.getReturningAttributes()) { if (DEBUG) { DEBUGGER.debug("returningAttribute: {}", returningAttribute); } userAccount.add(resultSet.getString(returningAttribute)); } if (DEBUG) { DEBUGGER.debug("List<Object>: {}", userAccount); } } } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } finally { try { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } } return userAccount; }