List of usage examples for java.sql SQLException toString
public String toString()
From source file:eionet.gdem.qa.XQueryService.java
/** * Checks if the job is ready (or error) and returns the result (or error message). * * @param jobId/*from w ww . j a v a 2 s .c o m*/ * @return Hash including code and result */ public Hashtable getResult(String jobId) throws GDEMException { LOGGER.info("XML/RPC call for getting result with JOB ID: " + jobId); String[] jobData = null; HashMap scriptData = null; int status = 0; try { jobData = xqJobDao.getXQJobData(jobId); if (jobData == null) { // no such job // throw new GDEMException("** No such job with ID=" + jobId + " in the queue."); status = Constants.XQ_JOBNOTFOUND_ERR; } else { scriptData = queryDao.getQueryInfo(jobData[5]); status = Integer.valueOf(jobData[3]).intValue(); } } catch (SQLException sqle) { throw new GDEMException("Error gettign XQJob data from DB: " + sqle.toString()); } LOGGER.info("XQueryService found status for job (" + jobId + "):" + String.valueOf(status)); Hashtable ret = result(status, jobData, scriptData, jobId); if (LOGGER.isInfoEnabled()) { String result = ret.toString(); if (result.length() > 100) { result = result.substring(0, 100).concat("...."); } LOGGER.info("result: " + result); } return ret; }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
@Test public void QueryResultTest01() { final String sql = "SELECT TOP(word, 10), COUNT(*) FROM publicdata:samples.shakespeare"; final String description = "The top 10 word from shakespeare #TOP #COUNT"; String[][] expectation = new String[][] { { "you", "yet", "would", "world", "without", "with", "your", "young", "words", "word" }, { "42", "42", "42", "42", "42", "42", "41", "41", "41", "41" } }; /** somehow the result changed with time { "you", "yet", "would", "world", "without", "with", "will", "why", "whose", "whom" },/*www. ja v a 2s . c om*/ { "42", "42", "42", "42", "42", "42", "42", "42", "42", "42" } }; */ this.logger.info("Test number: 01"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try { Result = QueryResultTest.con.createStatement().executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); HelperFunctions.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:org.apache.openjpa.jdbc.sql.MySQLDictionary.java
@Override protected int matchErrorState(Map<Integer, Set<String>> errorStates, SQLException ex) { int state = super.matchErrorState(errorStates, ex); // OPENJPA-1616 - Special case for MySQL not returning a SQLState for timeouts if (state == StoreException.GENERAL && ex.getErrorCode() == 0 && ex.getSQLState() == null) { // look at the nested MySQL exception for more details SQLException sqle = ex.getNextException(); if (sqle != null && sqle.toString().startsWith("com.mysql.jdbc.exceptions.MySQLTimeoutException")) { if (conf != null && conf.getLockTimeout() != -1) { state = StoreException.LOCK; } else { state = StoreException.QUERY; }/*from w w w . j av a 2 s. c o m*/ } } return state; }
From source file:eionet.gdem.qa.XQueryService.java
/** * Request from XML/RPC client Stores the xqScript and starts a job in the workqueue. * * @param sourceURL - URL of the source XML * @param xqScript - XQueryScript to be processed * @param scriptType - xquery, xsl or xgawk *//*from w w w. j a v a 2s. c om*/ public String analyze(String sourceURL, String xqScript, String scriptType) throws GDEMException { String xqFile = ""; LOGGER.info("XML/RPC call for analyze xml: " + sourceURL); // save XQScript in a text file for the WQ try { xqFile = Utils.saveStrToFile(xqScript, scriptType); } catch (FileNotFoundException fne) { throw new GDEMException("Folder does not exist: :" + fne.toString()); } catch (IOException ioe) { throw new GDEMException("Error storing XQScript into file:" + ioe.toString()); } // name for temporary output file where the esult is stored: String resultFile = Properties.tmpFolder + File.separatorChar + "gdem_" + System.currentTimeMillis() + ".html"; String newId = "-1"; // should not be returned with value -1; // start a job in the Workqueue try { // get the trusted URL from source file adapter sourceURL = SourceFileManager.getSourceFileAdapterURL(getTicket(), sourceURL, isTrustedMode()); newId = xqJobDao.startXQJob(sourceURL, xqFile, resultFile); } catch (SQLException sqe) { sqe.printStackTrace(); LOGGER.error("DB operation failed: " + sqe.toString()); throw new GDEMException("DB operation failed: " + sqe.toString()); } catch (MalformedURLException e) { e.printStackTrace(); LOGGER.error("Source file URL is wrong: " + e.toString()); throw new GDEMException("Source file URL is wrong: " + e.toString()); } catch (IOException e) { e.printStackTrace(); LOGGER.error("Error opening source file: " + e.toString()); throw new GDEMException("Error opening source file: " + e.toString()); } return newId; }
From source file:eionet.gdem.qa.XQueryService.java
/** * *//*from ww w . ja v a2 s . c om*/ public Vector analyzeXMLFiles(String schema, String origFile, Vector result) throws GDEMException { LOGGER.info("XML/RPC call for analyze xml: " + origFile); if (result == null) { result = new Vector(); } Vector outputTypes = null; // get all possible xqueries from db String newId = "-1"; // should not be returned with value -1; String file = origFile; Vector queries = listQueries(schema); try { outputTypes = convTypeDao.getConvTypes(); } catch (SQLException sqe) { throw new GDEMException("DB operation failed: " + sqe.toString()); } try { // get the trusted URL from source file adapter file = SourceFileManager.getSourceFileAdapterURL(getTicket(), file, isTrustedMode()); } catch (Exception e) { String err_mess = "File URL is incorrect"; LOGGER.error(err_mess + "; " + e.toString()); throw new GDEMException(err_mess, e); } if (!Utils.isNullVector(queries)) { for (int j = 0; j < queries.size(); j++) { Hashtable query = (Hashtable) queries.get(j); String query_id = String.valueOf(query.get("query_id")); String queryFile = (String) query.get("query"); String contentType = (String) query.get("content_type_id"); String fileExtension = getExtension(outputTypes, contentType); String resultFile = Properties.tmpFolder + File.separatorChar + "gdem_q" + query_id + "_" + System.currentTimeMillis() + "." + fileExtension; try { int queryId = 0; try { queryId = Integer.parseInt(query_id); } catch (NumberFormatException n) { queryId = 0; } // if it is a XQuery script, then append the system folder if (queryId != Constants.JOB_VALIDATION && queryFile.startsWith(Properties.gdemURL + "/" + Constants.QUERIES_FOLDER)) { queryFile = Utils.Replace(queryFile, Properties.gdemURL + "/" + Constants.QUERIES_FOLDER, Properties.queriesFolder + File.separator); } newId = xqJobDao.startXQJob(file, queryFile, resultFile, queryId); } catch (SQLException sqe) { throw new GDEMException("DB operation failed: " + sqe.toString()); } Vector queryResult = new Vector(); queryResult.add(newId); queryResult.add(origFile); result.add(queryResult); } } LOGGER.info("Analyze xml result: " + result.toString()); return result; }
From source file:org.apache.openaz.xacml.std.pip.engines.jdbc.JDBCEngine.java
protected void getAttributes(PIPRequest pipRequest, PIPFinder pipFinder, JDBCResolver jdbcResolver, StdMutablePIPResponse pipResponse) throws PIPException { /*/*from www.j a va2s . c o m*/ * First we need to get a PreparedStatement */ Connection connection = this.getConnection(); PreparedStatement preparedStatement = jdbcResolver.getPreparedStatement(this, pipRequest, pipFinder, connection); if (preparedStatement == null) { this.logger.debug(this.getName() + " does not handle " + pipRequest.toString()); try { if (connection != null) { connection.close(); } } catch (Exception e) { //NOPMD } return; } /* * Is it in the cache? */ this.logger.debug(preparedStatement.toString()); // Cache<String, PIPResponse> cache = this.getCache(); //if (cache != null) { // TODO - a cache key //} /* * Execute the prepared statement */ ResultSet resultSet = null; try { resultSet = preparedStatement.executeQuery(); } catch (SQLException ex) { this.logger.error("SQLException executing query: " + ex.toString(), ex); // TODO: Should we re-throw the exception, or just return an empty response? } if (resultSet == null) { try { preparedStatement.close(); } catch (SQLException e) { this.logger.error("SQLException closing preparedStatment: " + e.toString(), e); } try { if (connection != null) { connection.close(); } } catch (Exception e) { //NOPMD } return; } try { /* * Get all the results */ while (resultSet.next()) { List<Attribute> listAttributes = jdbcResolver.decodeResult(resultSet); if (listAttributes != null) { pipResponse.addAttributes(listAttributes); } } /* * Save it in the cache */ //if (cache != null) { // TODO //} } catch (SQLException ex) { this.logger.error("SQLException decoding results: " + ex.toString()); // TODO: Should we re-throw the exception or just continue } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { this.logger.error("SQLException closing resultSet: " + e.toString() + " (May be memory leak)"); } } try { preparedStatement.close(); } catch (SQLException e) { this.logger.error( "SQLException closing preparedStatement: " + e.toString() + " (May be memory leak)"); } try { connection.close(); } catch (SQLException e) { this.logger.error("SQLException closing connection: " + e.toString() + " (May be memory leak)"); } } }
From source file:org.apache.hive.jdbc.HiveQueryResultSet.java
private void closeOperationHandle(TOperationHandle stmtHandle) throws SQLException { try {/*from w w w . ja va 2s .co m*/ if (stmtHandle != null) { TCloseOperationReq closeReq = new TCloseOperationReq(stmtHandle); TCloseOperationResp closeResp = client.CloseOperation(closeReq); Utils.verifySuccessWithInfo(closeResp.getStatus()); } } catch (SQLException e) { throw e; } catch (Exception e) { throw new SQLException(e.toString(), "08S01", e); } }
From source file:rpassmore.app.fillthathole.ViewHazardActivity.java
/** * loads the hazard and populates the ui from the id supplied in the bundle * @param b// w ww . j a v a 2 s . co m * @return bool - true if a hazard was loaded */ private boolean createFromBundle(Bundle b) { if (b != null) { long id = b.getLong(SAVED_HAZARD_ID); if (id == -1) { hazard = new Hazard(); } else { try { dbAdapter.open(); hazard = dbAdapter.load(id); populateFromHazard(); makeActivityReadOnly(); } catch (SQLException e) { Log.e(getPackageName(), e.toString()); } finally { dbAdapter.close(); } } return true; } return false; }
From source file:com.redoute.datamap.dao.impl.PictureDAO.java
@Override public void deletePicture(Picture picture) { StringBuilder query = new StringBuilder(); query.append("delete from picture where `id`=? "); Connection connection = this.databaseSpring.connect(); try {/* w ww. j a v a 2 s. com*/ PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, picture.getId().toString()); preStat.executeUpdate(); } catch (SQLException exception) { Logger.log(PictureDAO.class.getName(), Level.ERROR, exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { Logger.log(PictureDAO.class.getName(), Level.ERROR, exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { Logger.log(PictureDAO.class.getName(), Level.WARN, e.toString()); } } pictureFileHelper.save(picture, false); }
From source file:com.redoute.datamap.dao.impl.PictureDAO.java
private void updateDatabasePicture(String id, String columnName, String value) { boolean throwExcep = false; StringBuilder query = new StringBuilder(); query.append("update picture set `"); query.append(columnName);/*from w w w . j a v a 2 s. c o m*/ query.append("`=? where `id`=? "); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, value); preStat.setString(2, id); preStat.executeUpdate(); throwExcep = false; } catch (SQLException exception) { Logger.log(PictureDAO.class.getName(), Level.ERROR, exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { Logger.log(PictureDAO.class.getName(), Level.ERROR, exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { Logger.log(PictureDAO.class.getName(), Level.WARN, e.toString()); } } }