List of usage examples for java.sql SQLException getSQLState
public String getSQLState()
SQLException
object. From source file:org.apache.hive.jdbc.TestSSL.java
/*** * Test non-SSL client with SSL server fails * @throws Exception/*from ww w. jav a 2s .c o m*/ */ @Test public void testConnectionMismatch() throws Exception { setSslConfOverlay(confOverlay); // Test in binary mode setBinaryConfOverlay(confOverlay); miniHS2.start(confOverlay); // Start HS2 with SSL try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL(), System.getProperty("user.name"), "bar"); fail("NON SSL connection should fail with SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL() + ";ssl=false", System.getProperty("user.name"), "bar"); fail("NON SSL connection should fail with SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } miniHS2.stop(); // Test in http mode setHttpConfOverlay(confOverlay); miniHS2.start(confOverlay); try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL("default", ";ssl=false"), System.getProperty("user.name"), "bar"); fail("NON SSL connection should fail with SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } }
From source file:org.apache.hive.jdbc.TestSSL.java
/*** * Test SSL client with non-SSL server fails * @throws Exception/*from w ww . ja v a2s .co m*/ */ @Test public void testInvalidConfig() throws Exception { clearSslConfOverlay(confOverlay); // Test in binary mode setBinaryConfOverlay(confOverlay); miniHS2.start(confOverlay); DriverManager.setLoginTimeout(4); try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL("default", SSL_CONN_PARAMS), System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } System.setProperty(JAVA_TRUST_STORE_PROP, dataFileDir + File.separator + TRUST_STORE_NAME); System.setProperty(JAVA_TRUST_STORE_PASS_PROP, KEY_STORE_PASSWORD); try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL() + ";ssl=true", System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } miniHS2.stop(); // Test in http mode with ssl properties specified in url System.clearProperty(JAVA_TRUST_STORE_PROP); System.clearProperty(JAVA_TRUST_STORE_PASS_PROP); setHttpConfOverlay(confOverlay); miniHS2.start(confOverlay); try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL("default", SSL_CONN_PARAMS), System.getProperty("user.name"), "bar"); fail("SSL connection should fail with NON-SSL server"); } catch (SQLException e) { // expected error assertEquals("08S01", e.getSQLState().trim()); } }
From source file:org.wso2.andes.store.rdbms.RDBMSStoreUtils.java
/** * Extracts SQL State from a given sql exception * /* w w w.j a va 2 s . c om*/ * @param sqlException * the error * @return sql state */ private String extractSqlState(SQLException sqlException) { String sqlState = sqlException.getSQLState(); SQLException nextEx = sqlException.getNextException(); while (sqlState == null && nextEx != null) { sqlState = nextEx.getSQLState(); nextEx = nextEx.getNextException(); } return sqlState; }
From source file:com.pontecultural.flashcards.ReadSpreadsheet.java
public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equals(TAG_FOR_TEXT)) { if (inSrcLang == true) { inSrcLang = false;/*from w w w . j a va2s.c om*/ srcColumnSetP = true; } else if (inDestLang == true) { inDestLang = false; srcColumnSetP = false; } } else if (qName.equals(TAG_FOR_CARD)) { if (!(srcPhrase.isEmpty() && destPhrase.isEmpty())) { if (inDescription) { logger.debug("deck name: " + deckName + " - " + destPhrase + "\n"); Deck d = new Deck(deckName, destPhrase); try { this.deckId = this.jdbcFlashcardsDao.insert(d); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error(e.getCause().getMessage()); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); } testCountDecks++; } else { Card c = new Card(srcPhrase, destPhrase, deckId); try { this.jdbcFlashcardsDao.insert(c); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error(e.getCause().getMessage()); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); } catch (Exception e) { logger.error("hmm..what happened here: " + e.getMessage()); } logger.debug("card completed"); logger.debug("\t en: " + srcPhrase); logger.debug("\t pt: " + destPhrase); testCountCards++; } this.initializeCardState(); } } else if (qName.equals(TAG_FOR_DECK)) { logger.debug("deck completed."); } }
From source file:org.apache.openjpa.jdbc.sql.SybaseDictionary.java
public boolean isFatalException(int subtype, SQLException ex) { if (subtype == StoreException.LOCK) { SQLException next = ex.getNextException(); if ("JZ0TO".equals(next.getSQLState())) { return false; // query timeout }/* w w w . j a v a2 s .c o m*/ } return super.isFatalException(subtype, ex); }
From source file:com.mirth.connect.server.Mirth.java
private void stopDatabase() { String database = mirthProperties.getString("database"); if (database.equals("derby")) { boolean gotException = false; try {/*from w w w . j a v a 2 s. com*/ DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (SQLException sqle) { if ((sqle.getSQLState() != null) && sqle.getSQLState().equals("XJ015")) { gotException = true; } } if (gotException) { System.out.println("Database shut down normally."); } } }
From source file:com.flexive.core.storage.PostgreSQL.PostgreSQLStorageFactory.java
/** * {@inheritDoc}/*from w w w .j a va 2 s. c o m*/ */ @Override public boolean isDuplicateKeyViolation(SQLException exc) { //see http://www.postgresql.org/docs/8.4/interactive/errcodes-appendix.html return "42710".equals(exc.getSQLState()) || "23505".equals(exc.getSQLState()); }
From source file:org.apache.hive.jdbc.TestSSL.java
/*** * Tests to ensure SSLv2 and SSLv3 are disabled *//*from w w w. j a v a 2s . c o m*/ @Test public void testSSLVersion() throws Exception { Assume.assumeTrue(execCommand("which openssl") == 0); // we need openssl Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("linux")); // we depend on linux openssl exit codes setSslConfOverlay(confOverlay); // Test in binary mode setBinaryConfOverlay(confOverlay); // Start HS2 with SSL miniHS2.start(confOverlay); // make SSL connection hs2Conn = DriverManager .getConnection( miniHS2.getJdbcURL() + ";ssl=true;sslTrustStore=" + dataFileDir + File.separator + TRUST_STORE_NAME + ";trustStorePassword=" + KEY_STORE_PASSWORD, System.getProperty("user.name"), "bar"); hs2Conn.close(); Assert.assertEquals("Expected exit code of 1", 1, execCommand("openssl s_client -connect " + miniHS2.getHost() + ":" + miniHS2.getBinaryPort() + " -ssl2 < /dev/null")); Assert.assertEquals("Expected exit code of 1", 1, execCommand("openssl s_client -connect " + miniHS2.getHost() + ":" + miniHS2.getBinaryPort() + " -ssl3 < /dev/null")); miniHS2.stop(); // Test in http mode setHttpConfOverlay(confOverlay); miniHS2.start(confOverlay); // make SSL connection try { hs2Conn = DriverManager.getConnection(miniHS2.getJdbcURL() + ";ssl=true;sslTrustStore=" + dataFileDir + File.separator + TRUST_STORE_NAME + ";trustStorePassword=" + KEY_STORE_PASSWORD + "?hive.server2.transport.mode=" + HS2_HTTP_MODE + ";hive.server2.thrift.http.path=" + HS2_HTTP_ENDPOINT, System.getProperty("user.name"), "bar"); Assert.fail("Expected SQLException during connect"); } catch (SQLException e) { LOG.info("Expected exception: " + e, e); Assert.assertEquals("08S01", e.getSQLState().trim()); Throwable cause = e.getCause(); Assert.assertNotNull(cause); while (cause.getCause() != null) { cause = cause.getCause(); } Assert.assertEquals("org.apache.http.NoHttpResponseException", cause.getClass().getName()); Assert.assertTrue(cause.getMessage().contains("failed to respond")); } miniHS2.stop(); }
From source file:com.eucalyptus.reporting.dw.commands.CommandSupport.java
protected void handleCommandError(final Throwable e) { if (e instanceof ConfigurationException) { System.err.println("Missing or invalid configuration."); System.err.println(e.getMessage()); return;//from ww w . j a v a2s .c o m } if (e instanceof ArgumentException) { System.err.println("Missing or invalid arguments."); System.err.println(e.getMessage()); return; } if (Exceptions.isCausedBy(e, CertificateNotTrustedException.class)) { final CertificateNotTrustedException certificateNotTrustedException = Exceptions.findCause(e, CertificateNotTrustedException.class); System.err.println("Database access failed due to untrusted server certificate."); System.err.println("Issuer : " + certificateNotTrustedException.getIssuer()); System.err.println("Serial : " + certificateNotTrustedException.getSerialNumber()); System.err.println("Subject : " + certificateNotTrustedException.getSubject()); System.err.println("SHA-1 Fingerprint: " + certificateNotTrustedException.getSha1Fingerprint()); return; } if (Exceptions.isCausedBy(e, PersistenceException.class) && Exceptions.isCausedBy(e, SQLException.class)) { final SQLException sqlException = Exceptions.findCause(e, SQLException.class); System.err.println("Database access failed with the following details."); System.err.println("SQLState : " + sqlException.getSQLState()); System.err.println("Error Code: " + sqlException.getErrorCode()); System.err.println(sqlException.getMessage()); return; } System.err.println("Error processing command: " + e.getMessage()); Logger.getLogger(this.getClass()).error("Error processing command", e); System.exit(1); }
From source file:com.hangum.tadpole.rdb.core.editors.objectmain.ObjectEditor.java
/** * mssql after process/* ww w . j a va2s . c o m*/ * @param reqResultDAO * @param reqQuery */ private void mssqlAfterProcess(RequestResultDAO reqResultDAO, RequestQuery reqQuery) { if (reqResultDAO.getException() == null) return; String strSQLState = ""; int intSQLErrorCode = -1; Throwable cause = reqResultDAO.getException(); ; if (cause instanceof SQLException) { try { SQLException sqlException = (SQLException) cause; strSQLState = sqlException.getSQLState(); intSQLErrorCode = sqlException.getErrorCode(); if (logger.isDebugEnabled()) logger.debug("==========> SQLState : " + strSQLState + "\t SQLErrorCode : " + intSQLErrorCode); } catch (Exception e) { logger.error("SQLException to striing", e); //$NON-NLS-1$ } } if (strSQLState.equals("S0001") && intSQLErrorCode == 2714) { //$NON-NLS-1$ String cmd = String.format("DROP %s %s", reqQuery.getSqlDDLType(), reqQuery.getSqlObjectName()); //$NON-NLS-1$ if (MessageDialog.openConfirm(null, Messages.get().Confirm, String.format(Messages.get().ObjectEditor_13, reqQuery.getSqlObjectName()))) { RequestResultDAO reqReResultDAO = new RequestResultDAO(); try { reqReResultDAO = ExecuteDDLCommand.executSQL(userDB, cmd); //$NON-NLS-1$ afterProcess(reqQuery, reqReResultDAO, Messages.get().ObjectEditor_2); reqReResultDAO = ExecuteDDLCommand.executSQL(userDB, reqQuery.getOriginalSql()); //$NON-NLS-1$ afterProcess(reqQuery, reqReResultDAO, Messages.get().ObjectEditor_2); } catch (Exception ee) { afterProcess(reqQuery, reqResultDAO, ""); //$NON-NLS-1$ } } } }