List of usage examples for java.sql SQLException SQLException
public SQLException(String reason, Throwable cause)
SQLException
object with a given reason
and cause
. From source file:com.sf.ddao.factory.param.ParameterHelper.java
public int bindParam(PreparedStatement preparedStatement, int idx, Context context) throws SQLException { Object param = extractParam(context); log.debug("query parameter {}={}", name, param); try {/*w w w .j a va2s . co m*/ if (param instanceof BoundParameter) { BoundParameter statementParamter = (BoundParameter) param; int res = statementParamter.bindParam(preparedStatement, idx, context); assert res == 1; } else { bind(preparedStatement, idx, param, context); } } catch (Exception e) { throw new SQLException("Failed to bindParam parameter " + name + " to index " + idx, e); } return 1; }
From source file:net.hydromatic.optiq.impl.splunk.SplunkDriver.java
@Override public Connection connect(String url, Properties info) throws SQLException { Connection connection = super.connect(url, info); OptiqConnection optiqConnection = (OptiqConnection) connection; SplunkConnection splunkConnection;/*w w w .ja va 2 s. co m*/ try { String url1 = info.getProperty("url"); if (url1 == null) { throw new IllegalArgumentException("Must specify 'url' property"); } URL url2 = new URL(url1); String user = info.getProperty("user"); if (user == null) { throw new IllegalArgumentException("Must specify 'user' property"); } String password = info.getProperty("password"); if (password == null) { throw new IllegalArgumentException("Must specify 'password' property"); } splunkConnection = new SplunkConnection(url2, user, password); } catch (Exception e) { throw new SQLException("Cannot connect", e); } final MutableSchema rootSchema = optiqConnection.getRootSchema(); final String schemaName = "splunk"; final SplunkSchema schema = new SplunkSchema(optiqConnection, rootSchema, schemaName, splunkConnection, optiqConnection.getTypeFactory(), rootSchema.getSubSchemaExpression(schemaName, Schema.class)); rootSchema.addSchema(schemaName, schema); // Include a schema called "mysql" in every splunk connection. // This is a hack for demo purposes. TODO: Add a config file mechanism. if (true) { final String mysqlSchemaName = "mysql"; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { throw new SQLException(e); } BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:mysql://localhost"); dataSource.setUsername("foodmart"); dataSource.setPassword("foodmart"); JdbcSchema.create(optiqConnection.getRootSchema(), dataSource, "foodmart", "", mysqlSchemaName); } return connection; }
From source file:it.larusba.neo4j.jdbc.http.driver.Neo4jResponse.java
/** * Construct the object directly from the HttpResponse. * * @param response Http response/*from w ww. ja va2 s .co m*/ * @param mapper Jackson object mapper * @throws SQLException */ public Neo4jResponse(HttpResponse response, ObjectMapper mapper) throws SQLException { // Parse response headers if (response.getStatusLine() != null) { // SAve the http code this.code = response.getStatusLine().getStatusCode(); // If status code is 201, then we retrieve the Location header to keep the transaction url. if (this.code == HttpStatus.SC_CREATED) { this.location = response.getFirstHeader("Location").getValue(); } // Parsing the body HttpEntity json = response.getEntity(); if (json != null) { try (InputStream is = json.getContent()) { Map body = mapper.readValue(is, Map.class); // Error parsing this.errors = new ArrayList<>(); for (Map<String, String> error : (List<Map<String, String>>) body.get("errors")) { errors.add(new SQLException(error.getOrDefault("messages", ""), error.getOrDefault("code", ""))); } // Data parsing this.results = new ArrayList<>(); for (Map map : (List<Map>) body.get("results")) { results.add(new Neo4jResult(map)); } } catch (Exception e) { throw new SQLException(e); } } } else { throw new SQLException("Receive request without status code ..."); } }
From source file:org.ohmage.query.impl.SurveyResponseImageQueries.java
public List<UUID> getImageIdsFromSurveyResponse(UUID surveyResponseId) throws DataAccessException { try {//from ww w .j a v a 2 s . com return getJdbcTemplate().query(SQL_GET_IMAGE_IDS_FROM_SURVEY_RESPONSE, new Object[] { surveyResponseId.toString() }, new RowMapper<UUID>() { @Override public UUID mapRow(ResultSet rs, int rowNum) throws SQLException { String response = rs.getString("response"); try { return UUID.fromString(response); } catch (IllegalArgumentException notUuid) { try { NoResponse.valueOf(response.toUpperCase()); return null; } catch (IllegalArgumentException notNoResponse) { throw new SQLException("The response value is not a valid UUID.", notNoResponse); } } } }); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_IMAGE_IDS_FROM_SURVEY_RESPONSE + "' with parameter: " + surveyResponseId, e); } }
From source file:com.hortonworks.registries.storage.tool.shell.ShellMigrationExecutor.java
@Override public void execute(Connection connection) throws SQLException { String scriptLocation = this.shellScriptResource.getLocationOnDisk(); try {//from w w w . ja v a 2 s. co m List<String> args = new ArrayList<String>(); args.add(scriptLocation); ProcessBuilder builder = new ProcessBuilder(args); builder.redirectErrorStream(true); Process process = builder.start(); Scanner in = new Scanner(process.getInputStream()); System.out.println(StringUtils.repeat("+", 200)); while (in.hasNextLine()) { System.out.println(in.nextLine()); } int returnCode = process.waitFor(); System.out.println(StringUtils.repeat("+", 200)); if (returnCode != 0) { throw new FlywayException("script exited with value : " + returnCode); } } catch (Exception e) { LOG.error(e.toString()); // Only if SQLException or FlywaySqlScriptException is thrown flyway will mark the migration as failed in the metadata table throw new SQLException(String.format("Failed to run script \"%s\", %s", scriptLocation, e.getMessage()), e); } }
From source file:com.cws.esolutions.core.dao.impl.ApplicationDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IApplicationDataDAO#addApplication(java.util.List) *///from w w w .j a v a 2 s. c o m public synchronized void addApplication(final List<Object> value) throws SQLException { final String methodName = IApplicationDataDAO.CNAME + "#addApplication(final List<Object> value) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", value); } Map<Integer, Object> params = new HashMap<Integer, Object>(); params.put(1, (String) value.get(0)); params.put(2, (String) value.get(1)); params.put(3, (Double) value.get(2)); params.put(4, (String) value.get(3)); params.put(5, (String) value.get(4)); params.put(6, (String) value.get(5)); params.put(7, (String) value.get(6)); params.put(8, (String) value.get(7)); params.put(9, (String) value.get(8)); try { SQLUtils.addOrDeleteData("{CALL insertNewApplication(?, ?, ?, ?, ?, ?, ?, ?, ?)}", params); } catch (UtilityException ux) { throw new SQLException(ux.getMessage(), ux); } }
From source file:org.neo4j.jdbc.http.driver.Neo4jResponse.java
/** * Construct the object directly from the HttpResponse. * * @param response Http response//from ww w. j a va2 s . c o m * @param mapper Jackson object mapper */ public Neo4jResponse(HttpResponse response, ObjectMapper mapper) throws SQLException { // Parse response headers if (response.getStatusLine() != null) { // SAve the http code this.code = response.getStatusLine().getStatusCode(); // If status code is 201, then we retrieve the Location header to keep the transaction url. if (this.code == HttpStatus.SC_CREATED) { this.location = response.getFirstHeader("Location").getValue(); } // Parsing the body HttpEntity json = response.getEntity(); if (json != null) { try (InputStream is = json.getContent()) { Map body = mapper.readValue(is, Map.class); // Error parsing this.errors = new ArrayList<>(); for (Map<String, String> error : (List<Map<String, String>>) body.get("errors")) { String message = ""; String code = ""; if (error.get("message") != null) { message = error.get("message"); } if (error.get("code") != null) { code = error.get("code"); } errors.add(new SQLException(message, code)); } // Data parsing this.results = new ArrayList<>(); if (body.containsKey("results")) { for (Map map : (List<Map>) body.get("results")) { results.add(new Neo4jResult(map)); } } } catch (Exception e) { throw new SQLException(e); } } } else { throw new SQLException("Receive request without status code ..."); } }
From source file:com.axibase.tsd.driver.jdbc.strategies.Consumer.java
private static void fillErrors(List<ErrorSection> errorSections, StatementContext context) { SQLException sqlException = null; if (errorSections != null) { for (ErrorSection section : errorSections) { sqlException = new SQLException(section.getMessage(), section.getState()); List<StackTraceElement> list = getStackTrace(section); sqlException.setStackTrace(list.toArray(new StackTraceElement[list.size()])); context.addException(sqlException); }// w ww .j a va 2 s . co m } if (sqlException != null) { throw new AtsdRuntimeException(sqlException.getMessage(), sqlException); } }
From source file:com.frameworkset.commons.dbcp2.PoolingDataSource.java
/** * Close and free all {@link Connection}s from the pool. * @since 2.1//from www. ja va2 s. c o m */ public void close() throws Exception { try { _pool.close(); } catch (RuntimeException rte) { throw new RuntimeException(Utils.getMessage("pool.close.fail"), rte); } catch (Exception e) { throw new SQLException(Utils.getMessage("pool.close.fail"), e); } }