List of usage examples for java.sql SQLException getSQLState
public String getSQLState()
SQLException
object. From source file:com.splicemachine.derby.impl.load.HdfsImportIT.java
@Test public void testImportPipeSeparatedFile() throws Exception { // DB-4904: Graceful message instead of connection termination needed in case if quoteChar and // delimiterChar is the same char String tableName = "PIPE_SEPARATED"; TableDAO td = new TableDAO(methodWatcher.getOrCreateConnection()); td.drop(spliceSchemaWatcher.schemaName, tableName); Connection conn = methodWatcher.getOrCreateConnection(); conn.createStatement()/*from ww w .j a v a2 s. c o m*/ .executeUpdate(format("create table %s ", spliceSchemaWatcher.schemaName + "." + tableName) + "(firstc int primary key, secondc char(30), thirdc int, fourthc double)"); String csvLocation = getResourceDirectory() + "pipeSeparator.csv"; PreparedStatement ps = conn.prepareStatement(format("call SYSCS_UTIL.IMPORT_DATA(" + "'%s'," + // schema name "'%s'," + // table name "null," + // insert column list "'%s'," + // file path "'|'," + // column delimiter "'|'," + // character delimiter "null," + // timestamp format "null," + // date format "null," + // time format "%d," + // max bad records "'%s'," + // bad record dir "false," + // has one line records "null)", // char set spliceSchemaWatcher.schemaName, tableName, csvLocation, 0, BADDIR.getCanonicalPath())); try { ps.execute(); fail("Expected exception, column and char delims are same."); } catch (SQLException e) { assertEquals("Expected different SQLState for column delim matching char delim", "XIE0F", e.getSQLState()); } // assert we can still use connection // if we can query w/o exception, we're good conn.createStatement() .executeQuery(String.format("select * from %s.%s", spliceSchemaWatcher.schemaName, tableName)); }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * Check <i>SQLException</i> for foreign key violation. * @return true is sqlState is a foreign key violation and false other wise *//*ww w.j a va 2 s. c om*/ public boolean isForeignKeyError(SQLException e) { return e.getSQLState().equals("23503"); }
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * logs an sql exception// w w w . j av a 2s. c o m * @param message the message * @param se the exception */ protected void logException(String message, SQLException se) { if (message != null) { log.error(message); } log.error(" Reason: " + se.getMessage()); log.error(" State/Code: " + se.getSQLState() + "/" + se.getErrorCode()); log.debug(" dump:", se); }
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * logs an sql exception/*w ww . j a v a2 s. co m*/ * @param message the message * @param e the exception */ protected void logException(String message, SQLException e) { if (message != null) { log.error(message); } log.error(" Reason: " + e.getMessage()); log.error(" State/Code: " + e.getSQLState() + "/" + e.getErrorCode()); log.debug(" dump:", e); }
From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java
/** * @param usrPwd// w ww . j ava 2s .com */ private void doCheckPermissions(final Pair<String, String> usrPwd) { if (System.getProperty("user.name").equals("rods")) { String dbDriver = DBConnection.getInstance().getDriver(); String serverName = getServerName(); String dbName = getDatabaseName(); SQLException loginEx = DBConnection.getLoginException(); if (StringUtils.isNotEmpty(dbDriver) && dbDriver.equals("com.mysql.jdbc.Driver") && loginEx != null && StringUtils.isNotEmpty(loginEx.getSQLState()) && loginEx.getSQLState().equals("08001")) { boolean doFixIt = UIRegistry.displayConfirmLocalized("MISSING_PRIV_TITLE", "MISSING_PRIV", "MISSING_PRIV_FIX", "Cancel", JOptionPane.WARNING_MESSAGE); if (doFixIt) { DBConnection.getInstance().setServerName(serverName); // Needed for SchemaUpdateService Pair<String, String> itUP = getITUsernamePwd(); DBMSUserMgr mgr = DBMSUserMgr.getInstance(); try { if (mgr != null && mgr.connectToDBMS(itUP.first, itUP.second, serverName)) { boolean isOK = mgr.setPermissions(usrPwd.first, dbName, DBMSUserMgr.PERM_ALL_BASIC); UIRegistry.showLocalizedMsg( isOK ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.ERROR_MESSAGE, getResourceString("MISSING_PRIV_TITLE"), (isOK ? "MISSING_PRIV_OK" : "MISSING_PRIV_ERR")); mgr.close(); } else { UIRegistry.showError("MISSING_PRIV_NO_LOGIN"); } } catch (Exception ex) { ex.printStackTrace(); } } } } }
From source file:org.apache.qpid.server.store.derby.DerbyMessageStore.java
@Override public void close() throws Exception { _closed.getAndSet(true);// w w w.j av a 2s . c o m _stateManager.attainState(State.CLOSING); try { Connection conn = DriverManager.getConnection(_connectionURL + ";shutdown=true"); // Shouldn't reach this point - shutdown=true should throw SQLException conn.close(); _logger.error("Unable to shut down the store"); } catch (SQLException e) { if (e.getSQLState().equalsIgnoreCase(DERBY_SINGLE_DB_SHUTDOWN_CODE)) { //expected and represents a clean shutdown of this database only, do nothing. } else { _logger.error("Exception whilst shutting down the store: " + e); } } _stateManager.attainState(State.CLOSED); }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.MetaThesaurusToSQL.java
private HashMap<String, String> getSourceCodeAndPresentationIDsFromCUI(String cui) throws SQLException { StringBuffer stmtSource = new StringBuffer( "select " + SQLTableConstants.TBLCOL_PROPERTYID + ", " + SQLTableConstants.TBLCOL_VAL1 + " from ") .append(stc_.getTableName(SQLTableConstants.ENTITY_PROPERTY_MULTI_ATTRIBUTES)) .append(" where " + SQLTableConstants.TBLCOL_CODINGSCHEMEID + "= '" + codingSchemeName_ + "' AND " + stc_.entityCodeOrEntityId + " = ? AND " + SQLTableConstants.TBLCOL_TYPENAME + " = '" + SQLTableConstants.TBLCOLVAL_QUALIFIER + "' AND " + SQLTableConstants.TBLCOL_ATTRIBUTEVALUE + " = 'source-code'"); PreparedStatement getPossibleIds = null; ResultSet getPossibleIds_results = null; HashMap<String, String> propIdToSource = new HashMap(); try {//from w ww .j a v a2 s . c o m getPossibleIds = sqlConnection_.prepareStatement(stmtSource.toString()); getPossibleIds.setString(1, cui); getPossibleIds_results = getPossibleIds.executeQuery(); while (getPossibleIds_results.next()) { String propId = getPossibleIds_results.getString(SQLTableConstants.TBLCOL_PROPERTYID); String sourceValue = getPossibleIds_results.getString(SQLTableConstants.TBLCOL_VAL1); propIdToSource.put(propId, sourceValue); } getPossibleIds_results.close(); getPossibleIds.close(); return propIdToSource; } catch (SQLException e) { messages_.warn("Error getting Source and Id information from Presentation."); log.warn("Error getting Source and Id information from Presentation."); throw new SQLException(e.getMessage(), e.getSQLState()); } finally { try { if (getPossibleIds_results != null) { getPossibleIds_results.close(); } if (getPossibleIds != null) { getPossibleIds.close(); } } catch (SQLException e) { messages_.info("Error closing SQL connection."); log.info("Error closing SQL connection."); // Just a SQL Housekeeping error -- return our result anyway. return propIdToSource; } } }
From source file:org.getobjects.eoaccess.EOAdaptorChannel.java
/** * Internal method to create a JDBC PreparedStatement object for the given SQL * using the JDBC Connection assigned to the channel. Catches any SQLException * and puts it into the lastException ivar. * //from w ww. j a v a 2s.com * @return a JDBC PreparedStatement representing the SQL */ protected PreparedStatement _createPreparedStatement(String _sql) { if (this.connection == null || _sql == null || _sql.length() == 0) return null; try { final PreparedStatement stmt = this.connection.prepareStatement(_sql); return stmt; } catch (SQLException e) { /* SQLState: '42X05' = 'Table/View 'xyz' does not exist */ log.info("could not prepare SQL statement: " + _sql + " " + e.getSQLState(), e); this.lastException = e; return null; } }
From source file:je3.rmi.MudClient.java
/** Return the balance of the specified account */ public synchronized int getBalance(String name, String password) throws RemoteException, BankingException { int balance; try {/*from w w w .j a va2s.c om*/ // Get the balance balance = verify(name, password); // Commit the transaction db.commit(); } catch (SQLException e) { try { db.rollback(); } catch (Exception e2) {} throw new BankingException("SQLException: " + e.getMessage() + ": " + e.getSQLState()); } // Return the balance return balance; }
From source file:je3.rmi.MudClient.java
/** Close a named account */ public synchronized FunnyMoney closeAccount(String name, String password) throws RemoteException, BankingException { int balance = 0; Statement s = null;/*from w ww. jav a2 s. c o m*/ try { balance = verify(name, password); s = db.createStatement(); // Delete the account from the accounts table s.executeUpdate("DELETE FROM accounts " + "WHERE name = '" + name + "' " + " AND password = '" + password + "'"); // And drop the transaction history table for this account s.executeUpdate("DROP TABLE " + name + "_history"); db.commit(); } catch (SQLException e) { try { db.rollback(); } catch (Exception e2) {} throw new BankingException("SQLException: " + e.getMessage() + ": " + e.getSQLState()); } finally { try { s.close(); } catch (Exception e) {} } // Finally, return whatever balance remained in the account return new FunnyMoney(balance); }