List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:org.neo4j.jdbc.http.driver.Neo4jStatement.java
/** * Default constructor.//w w w. ja v a 2s .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 * @throws SQLException sqlexception */ 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<String, Object>(); } if (includeStats != null) { this.includeStats = includeStats; } else { this.includeStats = Boolean.FALSE; } }
From source file:com.splout.db.engine.JDBCManager.java
public static QueryResult convertResultSetToQueryResult(ResultSet rs, int maxResults) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); String[] columnNames = new String[columns]; for (int i = 0; i < columns; i++) { columnNames[i] = md.getColumnName(i); }//w w w. jav a 2 s. co m List<Object[]> list = new ArrayList<Object[]>(); while (rs.next() && list.size() < maxResults) { Object[] row = new Object[columns]; for (int i = 1; i <= columns; ++i) { row[i] = rs.getObject(i); } list.add(row); } if (list.size() == maxResults) { throw new SQLException("Hard limit on number of results reached (" + maxResults + "), please use a LIMIT for this query."); } return new QueryResult(columnNames, list); }
From source file:com.ea.core.orm.handle.impl.HibernateSqlORMHandle.java
@Override protected Object execute(ORMParamsDTO dto) throws Exception { // TODO Auto-generated method stub Session session = this.getHibernateSessionFactory().getCurrentSession(); final ORMParamsDTO tmp = dto; session.doWork(new Work() { @SuppressWarnings("rawtypes") public void execute(Connection connection) throws SQLException { // connectionJDBC // closeconnection System.out.println("sql:" + tmp.getSqlid()); PreparedStatement ps = connection.prepareStatement(tmp.getSqlid()); if (tmp.getParam() != null) { Object data = tmp.getParam(); if (data instanceof Object[]) { Object[] array = (Object[]) data; int index = 1; for (Object obj : array) { setParam(ps, index++, obj); }/*from w ww. j a v a 2s . c o m*/ ps.execute(); } else if (data instanceof Collection) { for (Object array : (Collection) data) { if (array instanceof Object[]) { int index = 1; for (Object obj : (Object[]) array) { setParam(ps, index++, obj); } ps.addBatch(); } else { throw new SQLException("SQL?Object[]???!"); } } ps.executeBatch(); } else { throw new SQLException( "SQL????Object[]???????CollectionObject[]!"); } } } }); return null; }
From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.BasicDataSourceWrapper.java
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException { // try { return (Boolean) invokeMethod(basicDataSource != null? basicDataSource : this, "isWrapperFor", iface); try {/* w ww .j av a2 s . co m*/ return (Boolean) invokeMethod(this, "isWrapperFor", iface); } catch (Exception ex) { throw new SQLException(ex); } }
From source file:net.fender.sql.SingleConnectionDataSource.java
@Override protected ManagedConnection getManagedConnection() throws SQLException { boolean aquired = false; try {/* w w w . ja va 2s . c om*/ aquired = connectionSemaphore.tryAcquire(lockTimeout, lockTimeUnit); } catch (InterruptedException e) { // } if (aquired) { try { if (validateConnectionOnAquire) { try { validateConnection(managedConnection); } catch (InvalidConnectionException e) { // maybe this old connection timed out, retry one time managedConnection = super.getManagedConnection(); } } return managedConnection; } catch (SQLException e) { close(managedConnection); throw e; } } else { throw new SQLException( "Timeout (" + lockTimeout + " " + lockTimeUnit + ") waiting for available connection."); } }
From source file:com.gs.obevo.db.impl.core.jdbc.SingleConnectionDataSource.java
@Override public <T> T unwrap(Class<T> iface) throws SQLException { throw new SQLException(this.getClass().getName() + " is not a wrapper."); }
From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java
public ParsedSelectData parseSelectSql(final String sql) throws SQLException { InterimParseResult parseResult = parseNextValue(sql, ORDER_BY); final List<OrderCondition> orderConditions; if (parseResult.delimiter == null) { orderConditions = new ArrayList<OrderCondition>(); } else {/*from www. j a v a2 s . c om*/ orderConditions = OrderConditionParser.doYourJob(parseResult.unparsedRest); } parseResult = parseNextValue(parseResult.parsedValue, WHERE); final String whereClause = parseResult.unparsedRest; final String selectClause = parseResult.parsedValue; final List<WhereCondition> whereConditions = WhereConditionParser.doYourJob(whereClause); parseResult = parseNextValue(selectClause, SPACE); // cuts command if (!parseResult.unparsedRest.toLowerCase().contains(FROM.toLowerCase())) { throw new SQLException("Missing FROM declaration in select statement: " + sql); } parseResult = parseNextValueByLastOccurrence(parseResult.unparsedRest, FROM); final List<String> selectedColumns = parseColumnList(parseResult.parsedValue); final List<TableId> selectedTables; if (sql.contains(JOIN)) { selectedTables = parseAnsiJoinStatement(parseResult.unparsedRest, whereConditions); } else { selectedTables = parseTableList(parseResult.unparsedRest); } if (selectedTables.size() == 1) { // simple select on only one table removeTableIdFromColumnNamesIfPresent(selectedTables.get(0), selectedColumns); } else { replaceAliasInWhereConditions(whereConditions, selectedTables); replaceAliasInSelectClause(selectedColumns, selectedTables); replaceAliasInOrderConditions(orderConditions, selectedTables); } ParsedSelectData toReturn = new ParsedSelectData(buildTableNameList(selectedTables), selectedColumns, whereConditions, orderConditions); checkForUnkownAliases(toReturn); return toReturn; }
From source file:com.taobao.adfs.database.tdhsocket.client.util.ConvertUtil.java
public static long getLongFromString(String stringVal) throws SQLException { if (StringUtils.isBlank(stringVal)) { return 0; }//w w w.j a v a2 s. c o m try { int decimalIndex = stringVal.indexOf("."); if (decimalIndex != -1) { double valueAsDouble = Double.parseDouble(stringVal); return (long) valueAsDouble; } return Long.parseLong(stringVal); } catch (NumberFormatException e) { throw new SQLException("Parse integer error:" + stringVal); } }
From source file:com.aoindustries.website.clientarea.accounting.MakePaymentNewCardAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { MakePaymentNewCardForm makePaymentNewCardForm = (MakePaymentNewCardForm) form; String accounting = makePaymentNewCardForm.getAccounting(); if (GenericValidator.isBlankOrNull(accounting)) { // Redirect back to credit-card-manager it no accounting selected return mapping.findForward("make-payment"); }/*from w w w . ja va 2 s. c o 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) { makePaymentNewCardForm .setFirstName(AddCreditCardAction.getFirstName(profile.getBillingContact(), locale)); makePaymentNewCardForm .setLastName(AddCreditCardAction.getLastName(profile.getBillingContact(), locale)); makePaymentNewCardForm.setCompanyName(profile.getName()); makePaymentNewCardForm.setStreetAddress1(profile.getAddress1()); makePaymentNewCardForm.setStreetAddress2(profile.getAddress2()); makePaymentNewCardForm.setCity(profile.getCity()); makePaymentNewCardForm.setState(profile.getState()); makePaymentNewCardForm.setPostalCode(profile.getZIP()); makePaymentNewCardForm.setCountryCode(profile.getCountry().getCode()); } else { BusinessAdministrator thisBA = aoConn.getThisBusinessAdministrator(); makePaymentNewCardForm.setFirstName(AddCreditCardAction.getFirstName(thisBA.getName(), locale)); makePaymentNewCardForm.setLastName(AddCreditCardAction.getLastName(thisBA.getName(), locale)); makePaymentNewCardForm.setStreetAddress1(thisBA.getAddress1()); makePaymentNewCardForm.setStreetAddress2(thisBA.getAddress2()); makePaymentNewCardForm.setCity(thisBA.getCity()); makePaymentNewCardForm.setState(thisBA.getState()); makePaymentNewCardForm.setPostalCode(thisBA.getZIP()); makePaymentNewCardForm.setCountryCode(thisBA.getCountry() == null ? "" : thisBA.getCountry().getCode()); } initRequestAttributes(request, getServlet().getServletContext()); // Prompt for amount of payment defaults to current balance. BigDecimal balance = business.getAccountBalance(); if (balance.signum() > 0) { makePaymentNewCardForm.setPaymentAmount(balance.toPlainString()); } else { makePaymentNewCardForm.setPaymentAmount(""); } request.setAttribute("business", business); return mapping.findForward("success"); }
From source file:org.owasp.webgoat.session.DatabaseUtilities.java
private static Connection makeConnection(String user, WebgoatContext context) throws SQLException { try {// w w w . jav a2 s . co m Class.forName(context.getDatabaseDriver()); if (context.getDatabaseConnectionString().contains("hsqldb")) return getHsqldbConnection(user, context); String userPrefix = context.getDatabaseUser(); String password = context.getDatabasePassword(); String url = context.getDatabaseConnectionString(); return DriverManager.getConnection(url, userPrefix + "_" + user, password); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); throw new SQLException("Couldn't load the database driver: " + cnfe.getLocalizedMessage()); } }