List of usage examples for java.sql SQLException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.seasar.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerBase.java
protected void throwSQLFailureException(String sql, SQLException e) { final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to execute the SQL!"); br.addItem("SQL File"); br.addElement(_sqlFile);//w w w . ja v a 2 s . c o m br.addItem("Executed SQL"); br.addElement(sql); br.addItem("SQLState"); br.addElement(e.getSQLState()); br.addItem("ErrorCode"); br.addElement(e.getErrorCode()); br.addItem("SQLException"); br.addElement(e.getClass().getName()); br.addElement(extractMessage(e)); final SQLException nextEx = e.getNextException(); if (nextEx != null) { br.addItem("NextException"); br.addElement(nextEx.getClass().getName()); br.addElement(extractMessage(nextEx)); final SQLException nextNextEx = nextEx.getNextException(); if (nextNextEx != null) { br.addItem("NextNextException"); br.addElement(nextNextEx.getClass().getName()); br.addElement(extractMessage(nextNextEx)); } } final String msg = br.buildExceptionMessage(); throw new SQLFailureException(msg, e); }
From source file:no.sintef.jarfter.PostgresqlInteractor.java
private void loginDB() { JSONParser parser = new JSONParser(); String endpoint;/*from www . jav a 2 s . c om*/ String username; String password; try { Object object = parser.parse(new FileReader("/usr/local/var/jarfter_config.json")); JSONObject jsonObject = (JSONObject) object; endpoint = (String) jsonObject.get("db_endpoint"); username = (String) jsonObject.get("db_username"); password = (String) jsonObject.get("db_password"); if (empty(endpoint) || empty(username) || empty(password)) { throw new IOException( "Json file did not contain one of the following: endpoint, username, password (" + empty(endpoint) + "," + empty(username) + "," + empty(password) + ")"); } conn = DriverManager.getConnection(endpoint, username, password); } catch (SQLException sqle) { String sqleMessage = sqle.getLocalizedMessage(); log("loginDB - Found SQLException: " + sqle.getErrorCode() + " - " + sqleMessage); error(sqle); if (sqleMessage.contains("password authentication failed")) { throw new JarfterException(JarfterException.Error.DATABASE_LOGIN_ERROR); } else if (sqleMessage.contains("FATAL: database") && sqleMessage.contains("does not exist")) { throw new JarfterException(JarfterException.Error.SQL_NO_DATABASE); } else if (sqleMessage.contains("Connection refused. Check that the hostname and port are correct")) { throw new JarfterException(JarfterException.Error.SQL_NO_ENDPOINT); } else { throw new JarfterException(sqle.getClass().getName(), sqle.getLocalizedMessage()); } } catch (IOException ioe) { log("loginDB - Found IOException"); error(ioe); throw new JarfterException(JarfterException.Error.DATABASE_JSON_ERROR); } catch (ParseException pex) { log("loginDB - Found ParseException"); error(pex); throw new JarfterException(JarfterException.Error.DATABASE_JSON_ERROR); } }
From source file:org.opencb.opencga.storage.variant.sqlite.VariantSqliteDBAdaptor.java
/** * @param region The region where variants must be searched * @param studyName The name of the study where variants are filed * @param options Optional arguments/*from w ww. java2 s . c o m*/ * @return */ @Override public QueryResult getAllVariantsByRegionAndStudy(Region region, String studyName, QueryOptions options) { Long start, end, dbStart, dbEnd; start = System.currentTimeMillis(); boolean includeSamples, includeStats, includeEffects; int pos, id = Integer.MIN_VALUE; String sql, chr, ref, alt; String columns = "variant.id_variant, variant.chromosome, variant.position, variant.ref, variant.alt,variant.id "; String joins = ""; Variant variant = null; XObject elem; QueryResult<Variant> queryResult = new QueryResult<>( String.format("%s:%d-%d", region.getChromosome(), region.getStart(), region.getEnd())); List<Variant> results = new LinkedList<>(); List<String> whereClauses = new ArrayList<>(10); if (!options.containsKey("samples") && !options.containsKey("stats") && !options.containsKey("effects")) { includeSamples = true; includeStats = true; includeEffects = true; } else { includeSamples = options.containsKey("samples") && options.getBoolean("samples"); includeStats = options.containsKey("stats") && options.getBoolean("stats"); includeEffects = options.containsKey("effects") && options.getBoolean("effects"); } if (includeSamples) { columns += ",variant_info.key, variant_info.value "; joins += " left join variant_info on variant.id_variant=variant_info.id_variant "; } if (includeStats) { columns += ",variant_stats.maf, variant_stats.mgf, variant_stats.allele_maf , variant_stats.genotype_maf , variant_stats.miss_allele , variant_stats.miss_gt , variant_stats.mendel_err, variant_stats.is_indel , variant_stats.cases_percent_dominant , variant_stats.controls_percent_dominant , variant_stats.cases_percent_recessive , variant_stats.controls_percent_recessive "; joins += " inner join variant_stats on variant_stats.chromosome=variant.chromosome AND variant_stats.position=variant.position AND variant_stats.allele_ref=variant.ref AND variant_stats.allele_alt=variant.alt "; } if (includeEffects) { // columns += ""; // joins += " inner join variant_effect on variant_effect.chromosome=variant.chromosome AND variant_effect.position=variant.position AND variant_effect.reference_allele=variant.ref AND variant_effect.alternative_allele = variant.alt "; } try { StringBuilder regionClauses = new StringBuilder(); regionClauses.append("( variant.chromosome='").append(region.getChromosome()).append("' AND "); regionClauses.append("variant.position>=").append(String.valueOf(region.getStart())).append(" AND "); regionClauses.append("variant.position<=").append(String.valueOf(region.getEnd())); regionClauses.append(" ) "); whereClauses.add(regionClauses.toString()); sql = "SELECT " + columns + " from variant " + joins; if (whereClauses.size() > 0) { StringBuilder where = new StringBuilder(" WHERE "); for (int i = 0; i < whereClauses.size(); i++) { where.append(whereClauses.get(i)); if (i < whereClauses.size() - 1) { where.append(" AND "); } } sql += where.toString() + " ORDER BY variant.id_variant "; } sql += ";"; dbStart = System.currentTimeMillis(); Iterator<XObject> it = sqliteManager.queryIterator(sql); dbEnd = System.currentTimeMillis(); queryResult.setDbTime(dbEnd - dbStart); while (it.hasNext()) { elem = it.next(); if (id != elem.getInt("id_variant")) { // new Elem id = elem.getInt("id_variant"); chr = elem.getString("chromosome"); pos = elem.getInt("position"); ref = elem.getString("ref"); alt = elem.getString("alt"); variant = new Variant(chr, pos, pos, ref, alt); variant.setId(elem.getString("id")); variant.setFormat(elem.getString("format")); if (includeStats) { variant.setStats(new VariantStats(chr, pos, ref, alt, elem.getDouble("maf"), elem.getDouble("mgf"), elem.getString("allele_maf"), elem.getString("genotype_maf"), elem.getInt("miss_allele"), elem.getInt("miss_gt"), elem.getInt("mendel_err"), elem.getInt("is_indel") == 1, elem.getDouble("cases_percent_dominant"), elem.getDouble("controls_percent_dominant"), elem.getDouble("cases_percent_recessive"), elem.getDouble("controls_percent_recessive"))); } if (includeEffects) { VariantEffect ve = new VariantEffect(); } if (variant != null) { results.add(variant); } } if (elem.getString("key") != null && elem.getString("value") != null) { variant.addAttribute(elem.getString("key"), elem.getString("value")); } } sqliteManager.disconnect(false); } catch (SQLException e) { System.err.println("getAllVariantsByRegion: " + e.getClass().getName() + ": " + e.getMessage()); } // System.out.println("Results"); // for (Variant v : results) { // System.out.println(v); // } queryResult.setResult(results); queryResult.setNumResults(results.size()); end = System.currentTimeMillis(); queryResult.setTime(end - start); return queryResult; }
From source file:com.app.test.controller.UserControllerTest.java
@Test public void testDeleteAccount() throws Exception { setUpCustomer();//from w ww .jav a 2s . c o m setUpRecaptchaUtil(true); setUpUserUtil(); SearchQuery searchQuery = new SearchQuery(); searchQuery.setUserId(_USER_ID); searchQuery.setKeywords("Test keywords"); searchQuery.setActive(true); int searchQueryId = SearchQueryUtil.addSearchQuery(searchQuery); SearchQueryPreviousResultUtil.addSearchQueryPreviousResult(searchQueryId, "1234"); SearchResult searchResult = new SearchResult(searchQueryId, "1234", "First Item", "$10.00", "$14.99", "http://www.ebay.com/itm/1234", "http://www.ebay.com/123.jpg"); SearchResultUtil.addSearchResult(searchResult); User user = UserUtil.getUserByUserId(_USER_ID); Assert.assertNotNull(user); MockHttpServletRequestBuilder request = post("/delete_account"); request.param("emailAddress", "test@test.com"); request.param("password", "password"); ResultActions resultActions = this.mockMvc.perform(request); resultActions.andExpect(status().is3xxRedirection()); resultActions.andExpect(view().name("redirect:log_out")); resultActions.andExpect(redirectedUrl("log_out")); user = UserUtil.getUserByUserId(_USER_ID); Assert.assertNull(user); try { SearchQueryUtil.getSearchQuery(searchQueryId); } catch (SQLException sqle) { Assert.assertEquals(SQLException.class, sqle.getClass()); } int searchQueryPreviousResultCount = SearchQueryPreviousResultUtil .getSearchQueryPreviousResultsCount(searchQueryId); Assert.assertEquals(0, searchQueryPreviousResultCount); List<SearchResult> searchResults = SearchResultUtil.getSearchQueryResults(searchQueryId); Assert.assertEquals(0, searchResults.size()); }
From source file:org.sakaiproject.search.component.service.impl.SearchIndexBuilderWorkerImpl.java
/** * @return/*from www .j av a 2 s . c o m*/ * @throws HibernateException */ public boolean getLockTransaction(long nodeLifetime, boolean forceLock) { if (searchIndexBuilderWorkerDao.isLockRequired()) { return getHardLock(nodeLifetime, forceLock); } else { try { updateNodeLock(nodeLifetime); } catch (SQLException e) { log.warn("Failed to update node lock " + e.getClass().getName() + " :" + e.getMessage()); } return true; } }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getToolCount() { String mysql = "SELECT registration, count(*) as site_count " + "FROM SAKAI_SITE_TOOL " + "where site_id not like '~%' and site_id not like '!%' " + "group by 1 " + "order by 2 desc"; String oracle = "SELECT registration, count(*) as site_count" + " FROM SAKAI_SITE_TOOL" + " where site_id not like '~%' and site_id not like '!%'" + " group by registration" + " order by site_count desc"; // This query uses only the main Sakai database, so do not specify the connection as it might be external List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getString(1)); info.add(result.getInt(2)); } catch (SQLException e) { log.error("getToolCount() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from w w w .j a va 2 s. c o m*/ return info; } }); return result; }
From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfXlsDataHandlerImpl.java
protected String buildWriteFailureMessage(File file, String tableDbName // basic , SQLException mainEx // an exception of main process , SQLException retryEx, DfDataRow retryDataRow // retry , List<String> columnNameList) { // supplement final ExceptionMessageBuilder br = new ExceptionMessageBuilder(); br.addNotice("Failed to register the table data."); br.addItem("Advice"); br.addElement("Please confirm the SQLException message."); final String advice = askAdvice(mainEx, getBasicProperties().getCurrentDBDef()); if (advice != null && advice.trim().length() > 0) { br.addElement("*" + advice); }/*from w w w . j a va 2 s .c o m*/ br.addItem("Xls File"); br.addElement(file); br.addItem("Table"); br.addElement(tableDbName); br.addItem("SQLException"); br.addElement(mainEx.getClass().getName()); br.addElement(mainEx.getMessage()); if (retryEx != null) { br.addItem("Non-Batch Retry"); br.addElement(retryEx.getClass().getName()); br.addElement(retryEx.getMessage()); br.addElement(columnNameList.toString()); br.addElement(retryDataRow.toString()); br.addElement("Row Number: " + retryDataRow.getRowNumber()); } final Map<String, Class<?>> bindTypeCacheMap = _bindTypeCacheMap.get(tableDbName); final Map<String, StringProcessor> stringProcessorCacheMap = _stringProcessorCacheMap.get(tableDbName); if (bindTypeCacheMap != null) { br.addItem("Bind Type"); final Set<Entry<String, Class<?>>> entrySet = bindTypeCacheMap.entrySet(); for (Entry<String, Class<?>> entry : entrySet) { final String columnName = entry.getKey(); StringProcessor processor = null; if (stringProcessorCacheMap != null) { processor = stringProcessorCacheMap.get(columnName); } final String bindType = entry.getValue().getName(); final String processorExp = (processor != null ? " (" + processor + ")" : ""); br.addElement(columnName + " = " + bindType + processorExp); } } return br.buildExceptionMessage(); }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getWeeklyTotalLogins() { String mysql = "select STR_TO_DATE(concat(date_format(ACTIVITY_DATE, '%x-%v'), ' Monday'),'%x-%v %W') as week_start," + " sum(ACTIVITY_COUNT) as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login'" + " group by 1"; String oracle = "select next_day(ACTIVITY_DATE - 7, 2) as week_start," + " sum(ACTIVITY_COUNT) as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login'" + " group by next_day(ACTIVITY_DATE - 7, 2)"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getWeeklyTotalLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/* w w w. j a va 2s. c o m*/ return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getDailyTotalLogins() { String mysql = "select date(ACTIVITY_DATE) as session_date, " + " ACTIVITY_COUNT as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login' " + " and ACTIVITY_DATE > DATE_SUB(CURDATE(), INTERVAL 90 DAY)" + " group by 1"; String oracle = "select trunc(ACTIVITY_DATE, 'DDD') as session_date," + " sum(ACTIVITY_COUNT) as user_logins" + " from " + getExternalDbNameAsPrefix() + "SST_SERVERSTATS" + " where EVENT_ID='user.login' " + " and ACTIVITY_DATE > (SYSDATE - 90)" + " group by trunc(ACTIVITY_DATE, 'DDD')"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getDailyTotalLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }// www . j a va 2 s . co m return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
public List<ServerWideStatsRecord> getDailyUniqueLogins() { String mysql = "select date(LOGIN_DATE) as session_date, " + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " where LOGIN_DATE > DATE_SUB(CURDATE(), INTERVAL 90 DAY)" + " group by 1"; String oracle = "select trunc(LOGIN_DATE, 'DDD') as session_date, " + " count(distinct user_id) as unique_users" + " from " + getExternalDbNameAsPrefix() + "SST_USERSTATS" + " where LOGIN_DATE > (SYSDATE - 90)" + " group by trunc(LOGIN_DATE, 'DDD')"; List result = sqlService.dbRead(getSqlForVendor(mysql, oracle), null, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { ServerWideStatsRecord info = new ServerWideStatsRecordImpl(); try { info.add(result.getDate(1)); info.add(result.getLong(2)); } catch (SQLException e) { log.error("getDailyUniqueLogins() exception: " + e.getClass() + ": " + e.getMessage()); return null; }/*from w ww . java2 s . com*/ return info; } }); // remove the last entry, as it might not be a complete period result.remove(result.size() - 1); return result; }