List of usage examples for java.sql SQLException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.oracle.tutorial.jdbc.CoffeesFrame.java
public void rowChanged(RowSetEvent event) { CachedRowSet currentRowSet = this.myCoffeesTableModel.coffeesRowSet; try {//from www . ja v a 2s . c o m currentRowSet.moveToCurrentRow(); myCoffeesTableModel = new CoffeesTableModel(myCoffeesTableModel.getCoffeesRowSet()); table.setModel(myCoffeesTableModel); } catch (SQLException ex) { JDBCTutorialUtilities.printSQLException(ex); // Display the error in a dialog box. JOptionPane.showMessageDialog(CoffeesFrame.this, new String[] { // Display a 2-line message ex.getClass().getName() + ": ", ex.getMessage() }); } }
From source file:org.jiemamy.eclipse.core.ui.composer.DbImporterWizardPage.java
/** * ??//from w w w .j av a2 s.com * * TODO ?????????????????? */ private void testConnection() { final Display display = getShell().getDisplay(); try { final Driver driver = DriverUtil.getDriverInstance(getDriverJarPaths(), getDriverClassName()); final Properties info = new Properties(); info.setProperty("user", getUsername()); info.setProperty("password", getPassword()); final String uri = getUri(); new Thread() { @Override public void run() { Connection connection = null; try { connection = driver.connect(uri, info); if (connection != null) { display.asyncExec(new Runnable() { public void run() { MessageDialog.openInformation(getShell(), "?", "???????"); // RESOURCE connectionSucceeded(); } }); } else { display.asyncExec(new OpenErrorMessageDialog("0", "null connection")); // RESOURCE } } catch (SQLException ex) { final String msg = ex.getClass().getName() + " " + ex.getMessage(); display.asyncExec(new OpenErrorMessageDialog("1", msg)); // RESOURCE } catch (Exception ex) { final String msg = ex.getClass().getName() + " " + ex.getMessage(); display.asyncExec(new OpenErrorMessageDialog("2", msg)); // RESOURCE } finally { DbUtils.closeQuietly(connection); } } }.start(); } catch (DriverNotFoundException ex) { display.asyncExec( new OpenErrorMessageDialog("3", ex.getClass().getName() + " " + ex.getMessage())); // RESOURCE } catch (InstantiationException ex) { display.asyncExec( new OpenErrorMessageDialog("4", ex.getClass().getName() + " " + ex.getMessage())); // RESOURCE } catch (IllegalAccessException ex) { display.asyncExec( new OpenErrorMessageDialog("5", ex.getClass().getName() + " " + ex.getMessage())); // RESOURCE } catch (IOException ex) { display.asyncExec( new OpenErrorMessageDialog("6", ex.getClass().getName() + " " + ex.getMessage())); // RESOURCE } catch (Exception ex) { display.asyncExec( new OpenErrorMessageDialog("7", ex.getClass().getName() + " " + ex.getMessage())); // RESOURCE } }
From source file:com.bzcentre.dapiPush.DapiReceiver.java
/** * @param user_id//from w ww . ja v a2 s. c o m * @param to_token * @return String inactive (is in black list), sent_request (unknow, still in progress), false (not in black list) */ private String inBlackList(String user_id, String to_token) { String check_sql; ResultSet result; check_sql = "SELECT `user_id`, UNIX_TIMESTAMP(timestamp) as timestamp, `state` FROM `notification_push_blacklist` " + "WHERE `to_token`='" + to_token + "'"; try { result = BLKCheck.executeQuery(check_sql); if (result.next()) { if (user_id.equals(result.getString("user_id"))) { return result.getString("state"); // sent_request, inactive } else { return null; } } } catch (SQLException e) { if (e.getClass().getName().equals("com.mysql.jdbc.CommunicationsException")) { Map<String, String> target = new HashMap<>(); target.put("BLKCheck", check_sql); result = this.rebuildDBConnection(target); try { if (result.next()) { if (user_id.equals(result.getString("user_id"))) { return result.getString("state"); // sent_request, inactive } else { return null; } } } catch (SQLException se) { NginxClojureRT.log.info(TAG + check_sql); e.printStackTrace(); return null; } } else { NginxClojureRT.log.info(TAG + check_sql); e.printStackTrace(); } return null; } return "false"; }
From source file:eionet.cr.dao.virtuoso.VirtuosoStagingDatabaseDAO.java
@Override public void finishRDFExport(int exportId, ExportRunner exportRunner, ExportStatus status) throws DAOException { ArrayList<Object> params = new ArrayList<Object>(); params.add(status.name());//from w w w . j a v a 2 s .co m params.add(exportRunner.getRowCount()); params.add(exportRunner.getSubjectCount()); params.add(exportRunner.getTripleCount()); params.add(exportRunner.missingConceptsToString()); params.add(StringUtils.join(exportRunner.getGraphs(), '\n')); params.add(exportId); Connection conn = null; try { conn = getSQLConnection(); SQLUtil.executeUpdate(FINISH_RDF_EXPORT_SQL, params, conn); } catch (SQLException e) { throw new DAOException("Finishing RDF export record failed with " + e.getClass().getSimpleName(), e); } finally { SQLUtil.close(conn); } }
From source file:eionet.cr.dao.virtuoso.VirtuosoStagingDatabaseDAO.java
@Override public void updateImportStatus(int databaseId, ImportStatus importStatus) throws DAOException { ArrayList<Object> params = new ArrayList<Object>(); params.add(importStatus.name());/*from w w w . j a v a2 s . c om*/ params.add(databaseId); Connection conn = null; try { conn = getSQLConnection(); SQLUtil.executeUpdate(UPDATE_IMPORT_STATUS_SQL, params, conn); } catch (SQLException e) { throw new DAOException("Updating database import status failed with " + e.getClass().getSimpleName(), e); } finally { SQLUtil.close(conn); } }
From source file:eionet.cr.dao.virtuoso.VirtuosoStagingDatabaseDAO.java
@Override public void appendToImportLog(int databaseId, String message) throws DAOException { ArrayList<Object> params = new ArrayList<Object>(); params.add(message);//from w w w.j a v a 2s . c o m params.add(databaseId); Connection conn = null; try { conn = getSQLConnection(); SQLUtil.executeUpdate(ADD_IMPORT_LOG_MESSAGE_SQL, params, conn); } catch (SQLException e) { throw new DAOException("Adding database import log message failed with " + e.getClass().getSimpleName(), e); } finally { SQLUtil.close(conn); } }
From source file:eionet.cr.dao.virtuoso.VirtuosoStagingDatabaseDAO.java
@Override public void updateExportStatus(int exportId, ExportStatus status) throws DAOException { ArrayList<Object> params = new ArrayList<Object>(); params.add(status.name());// ww w.ja v a 2 s . c o m params.add(exportId); Connection conn = null; try { conn = getSQLConnection(); SQLUtil.executeUpdate(UPDATE_EXPORT_STATUS_SQL, params, conn); } catch (SQLException e) { throw new DAOException( "Updating database RDF export status failed with " + e.getClass().getSimpleName(), e); } finally { SQLUtil.close(conn); } }
From source file:eionet.cr.dao.virtuoso.VirtuosoStagingDatabaseDAO.java
@Override public void appendToExportLog(int exportId, String message) throws DAOException { ArrayList<Object> params = new ArrayList<Object>(); params.add(message);/* w ww.ja va2s.c om*/ params.add(exportId); Connection conn = null; try { conn = getSQLConnection(); SQLUtil.executeUpdate(ADD_EXPORT_LOG_MESSAGE_SQL, params, conn); } catch (SQLException e) { throw new DAOException( "Adding database RDF export log message failed with " + e.getClass().getSimpleName(), e); } finally { SQLUtil.close(conn); } }
From source file:AIR.Common.DB.AbstractDLL.java
public MultiDataResultSet executeStatement(SQLConnection connection, String queryTemplate, SqlParametersMaps parameters, boolean useNoLock) throws ReturnStatusException { final String messageTemplate = "Exception %1$s executing query. Template is \"%2$s\". Final query is \"%3$s\". Exception message: %4$s."; String reformulatedQuery = reformulateQueryWithParametersSubstitution(queryTemplate, parameters); MultiDataResultSet results = null;//from w ww . j a va2 s . c om logQuery(reformulatedQuery); int currentTransactionIsolation = -1; PreparedStatement st = null; try { st = connection.prepareStatement(reformulatedQuery); if (useNoLock) { // if (not supported )then throw DBLockNotSupportedException DatabaseMetaData dbMetaData = connection.getMetaData(); if (dbMetaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED) == false) throw new DBLockNotSupportedException( String.format("Select NoLock DB unsupported on %1$s", connection.getCatalog())); // TODO shiva confirm if nolock() is same as // TRANSACTION_READ_UNCOMMITTED. currentTransactionIsolation = connection.getTransactionIsolation(); connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } @SuppressWarnings("unused") boolean gotResultSet = st.execute(); results = new MultiDataResultSet(st); } catch (SQLException ex) { _logger.error(String.format(messageTemplate, "SQLException", queryTemplate, reformulatedQuery, ex.getMessage()), ex); throw new ReturnStatusException(ex); // TODO Shiva throw a ReturnStatusException here instead. Discuss // first. } catch (Exception ex) { _logger.error(String.format(messageTemplate, ex.getClass().getName(), queryTemplate, reformulatedQuery, ex.getMessage()), ex); throw new ReturnStatusException(ex); } finally { try { if (currentTransactionIsolation != -1) connection.setTransactionIsolation(currentTransactionIsolation); } catch (SQLException ex) { _logger.error(String.format(messageTemplate, "SQLException", queryTemplate, reformulatedQuery, ex.getMessage())); throw new ReturnStatusException(ex); } finally { try { st.close(); } catch (Throwable t) { } } } return results; }
From source file:com.app.test.controller.SearchQueryControllerTest.java
@Test public void testDeleteSearchQuery() throws Exception { setUpUserUtil();// w w w .ja v a 2 s . co m SearchQuery activeSearchQuery = new SearchQuery(); activeSearchQuery.setUserId(_USER_ID); activeSearchQuery.setKeywords("First test keywords"); activeSearchQuery.setActive(true); int activeSearchQueryId = SearchQueryUtil.addSearchQuery(activeSearchQuery); SearchResult firstSearchResult = new SearchResult(activeSearchQueryId, "1234", "itemTitle", "$14.99", "$14.99", "http://www.ebay.com/itm/1234", "http://www.ebay.com/123.jpg"); SearchResultUtil.addSearchResult(firstSearchResult); SearchQueryPreviousResultUtil.addSearchQueryPreviousResult(activeSearchQuery.getSearchQueryId(), "100"); SearchQuery inactiveSearchQuery = new SearchQuery(); inactiveSearchQuery.setUserId(_USER_ID); inactiveSearchQuery.setKeywords("First test keywords"); inactiveSearchQuery.setActive(true); int inactiveSearchQueryId = SearchQueryUtil.addSearchQuery(inactiveSearchQuery); SearchResult secondSearchResult = new SearchResult(inactiveSearchQueryId, "2345", "itemTitle", "$14.99", "$14.99", "http://www.ebay.com/itm/2345", "http://www.ebay.com/234.jpg"); SearchResultUtil.addSearchResult(secondSearchResult); SearchQueryPreviousResultUtil.addSearchQueryPreviousResult(inactiveSearchQuery.getSearchQueryId(), "200"); this.mockMvc .perform(post("/delete_search_query").param("searchQueryId", String.valueOf(activeSearchQueryId))) .andExpect(status().isFound()).andExpect(view().name("redirect:view_search_queries")); try { SearchQueryUtil.getSearchQuery(activeSearchQuery.getSearchQueryId()); } catch (SQLException sqle) { Assert.assertEquals(SQLException.class, sqle.getClass()); } this.mockMvc .perform(post("/delete_search_query").param("searchQueryId", String.valueOf(inactiveSearchQueryId))) .andExpect(status().isFound()).andExpect(view().name("redirect:view_search_queries")); try { SearchQueryUtil.getSearchQuery(inactiveSearchQuery.getSearchQueryId()); } catch (SQLException sqle) { Assert.assertEquals(SQLException.class, sqle.getClass()); } List<SearchResult> searchResults = SearchResultUtil.getSearchQueryResults(activeSearchQueryId); List<String> searchQueryPreviousResults = SearchQueryPreviousResultUtil .getSearchQueryPreviousResults(activeSearchQueryId); Assert.assertEquals(0, searchResults.size()); Assert.assertEquals(0, searchQueryPreviousResults.size()); searchResults = SearchResultUtil.getSearchQueryResults(inactiveSearchQueryId); searchQueryPreviousResults = SearchQueryPreviousResultUtil .getSearchQueryPreviousResults(inactiveSearchQueryId); Assert.assertEquals(0, searchResults.size()); Assert.assertEquals(0, searchQueryPreviousResults.size()); }