java.sql

Class SQLException

Implemented Interfaces:
Serializable
Known Direct Subclasses:
BatchUpdateException, RowSetWarning, SerialException, SQLNestedException, SQLWarning, SyncFactoryException, SyncProviderException

public class SQLException
extends Exception

An exception that provides information on a database access error or other errors.

Each SQLException provides several kinds of information:

See Also:
Serialized Form

Constructor Summary

SQLException()
Constructs an SQLException object; the reason field defaults to null, the SQLState field defaults to null, and the vendorCode field defaults to 0.
SQLException(String reason)
Constructs an SQLException object with a reason; the SQLState field defaults to null, and the vendorCode field defaults to 0.
SQLException(String reason, String SQLState)
Constructs an SQLException object with the given reason and SQLState; the vendorCode field defaults to 0.
SQLException(String reason, String SQLState, int vendorCode)
Constructs a fully-specified SQLException object.

Method Summary

int
getErrorCode()
Retrieves the vendor-specific exception code for this SQLException object.
SQLException
getNextException()
Retrieves the exception chained to this SQLException object.
String
getSQLState()
Retrieves the SQLState for this SQLException object.
void
setNextException(SQLException ex)
Adds an SQLException object to the end of the chain.

Methods inherited from class java.lang.Throwable

fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

SQLException

public SQLException()
Constructs an SQLException object; the reason field defaults to null, the SQLState field defaults to null, and the vendorCode field defaults to 0.
Usages and Demos :

View More Examples of SQLException()
   1:             e.printStackTrace();
   2:             throw new SQLException();
   3:         } catch (IllegalAccessException e)
   4:         ...
   5:             e.printStackTrace();
   6:             throw new SQLException();
   7:         } catch (ClassNotFoundException e)
   8:         ...
   9:             e.printStackTrace();
  10:             throw new SQLException();
  11:         }

View Full Code Here
   1:         DataStoreException exception = new DataStoreException(
   2:             "Unable to find order", new SQLException());
   3: 
   4:         orderStoreControl.setThrowable(exception);

View Full Code Here
   1:     public void testVoidBlock() {
   2:         final Exception orig = new SQLException();
   3:         assertNull(orig.getMessage());
   4:         Exception caught = null;
   5:         Exceptions.VoidBlock block = new Exceptions.VoidBlock() {

View Full Code Here
   1:     public Object unwrap(Class type) throws SQLException {
   2:         throw new SQLException();
   3:     }
   4: }

View Full Code Here
   1:         } catch (PhysicalConnectionException e) {
   2:             SQLException sqlException = new SQLException();
   3:             sqlException.initCause(e);
   4:         ...
   5:         } catch (PhysicalConnectionException e) {
   6:             SQLException sqlException = new SQLException();
   7:             sqlException.initCause(e);
   8:             throw sqlException;
   9:         } finally {

View Full Code Here

SQLException

public SQLException(String reason)
Constructs an SQLException object with a reason; the SQLState field defaults to null, and the vendorCode field defaults to 0.
Parameters:
reason - a description of the exception
Usages and Demos :

View More Examples of SQLException(String reason)
   1: 
   2:             throw new SQLException("ERROR: deleted " + n + " rows!!");
   3:         }
   4: 
   5:         users.remove(u);

View Full Code Here
   1:         } catch(ADQLException e) {
   2:             throw new SQLException("ADQLException");
   3:         }
   4:     }
   5:     public List getColumnList() throws ColumnNotFoundException {

View Full Code Here
   1:         } catch(ADQLException e) {
   2:             throw new SQLException("ADQLException");
   3:         }
   4:     }
   5:     public List getColumnList() throws ColumnNotFoundException {

View Full Code Here
   1:             e.printStackTrace();
   2:             throw new SQLException("ADQLException");
   3:         }
   4:     }
   5:     

View Full Code Here
   1:             e.printStackTrace();
   2:             throw new SQLException("ADQLException");
   3:         }
   4:     }
   5:     

View Full Code Here

SQLException

public SQLException(String reason,
                    String SQLState)
Constructs an SQLException object with the given reason and SQLState; the vendorCode field defaults to 0.
Parameters:
reason - a description of the exception
SQLState - an XOPEN or SQL 99 code identifying the exception
Usages and Demos :

View More Examples of SQLException(String reason,String SQLState)
   1:         sessionControl.setReturnValue(sf, 1);
   2:         SQLException sqlex = new SQLException("argh", "27");
   3:         session.flush();
   4:         sessionControl.setThrowable(new JDBCException(sqlex), 1);
   5:         session.close();

View Full Code Here
   1:         sessionControl.setReturnValue(sf, 1);
   2:         SQLException sqlex = new SQLException("argh", "27");
   3:         session.flush();
   4:         sessionControl.setThrowable(new JDBCException("", sqlex), 1);
   5:         session.close();

View Full Code Here
   1:             m_columnLastRead = INDEX_NULL;
   2:             throw new SQLException("RESULTSET_BEFORE_FIRST_ROW", String.valueOf(EOJ_RESULTSET_BEFORE_FIRST_ROW));
   3:         }
   4:         ...
   5:             m_columnLastRead = INDEX_NULL;
   6:             throw new SQLException("EXHAUSTED_RESULTSET", String.valueOf(EOJ_EXHAUSTED_RESULTSET));
   7:         }
   8:         ...
   9:         if (m_columnNames == null) {
  10:             throw new SQLException("NO_DESCRIPTOR", String.valueOf(EOJ_NO_DESCRIPTOR));
  11:         }

View Full Code Here
   1:         tx.commit();
   2:         SQLException sqlEx = new SQLException("argh", "27");
   3:         txControl.setThrowable(new JDBCException("mymsg", sqlEx), 1);
   4:         session.close();
   5:         sessionControl.setReturnValue(null, 1);

View Full Code Here
   1:         tx.commit();
   2:         SQLException sqlEx = new SQLException("argh", "27");
   3:         txControl.setThrowable(new JDBCException("mymsg", sqlEx), 1);
   4:         session.close();
   5:         sessionControl.setReturnValue(null, 1);

View Full Code Here

SQLException

public SQLException(String reason,
                    String SQLState,
                    int vendorCode)
Constructs a fully-specified SQLException object.
Parameters:
reason - a description of the exception
SQLState - an XOPEN or SQL 99 code identifying the exception
vendorCode - a database vendor-specific exception code
Usages and Demos :

View More Examples of SQLException(String reason,String SQLState,int vendorCode)
   1:         String sql = "SELECT FOO FROM BAR";
   2:         SQLException sex = new SQLException("Message", "42001", 1);
   3:         try {
   4:         ...
   5:         String sql = "SELECT FOO FROM BAR";
   6:         SQLException sex = new SQLException("Message", null, 1);
   7:         testMalformedSqlStateCode(sex);
   8:         ...
   9:         
  10:         sex = new SQLException("Message", "", 1);
  11:         testMalformedSqlStateCode(sex);

View Full Code Here
   1: 
   2:         SQLException badSqlEx = new SQLException("", "", 1);
   3:         BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", badSqlEx);
   4:         ...
   5: 
   6:         SQLException invResEx = new SQLException("", "", 4);
   7:         InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) sext.translate("task", "SQL", invResEx);
   8:         ...
   9: 
  10:         SQLException sex = new SQLException("", "07xxx", 666666666);
  11:         BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", sex);

View Full Code Here
   1:     {
   2:       throw new SQLException("createStatement(int,int,int) disallowed");      
   3:     }
   4:     public PreparedStatement prepareStatement(String sql,
   5:                                               int resultSetType,

View Full Code Here

Method Details

getErrorCode

public int getErrorCode()
Retrieves the vendor-specific exception code for this SQLException object.
Returns:
the vendor's error code
Usages and Demos :

View More Examples of getErrorCode()
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     public static boolean isDuplicateRowException(SQLException e) {
   7:         ...
   8:         if (e.getClass().getName().equals("com.ibm.db2.jcc.a.SqlException")) {
   9:         ...
  10:             return e.getErrorCode()==-803;

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5: 
   6:     private SQLException sqle;
   7:     private String sql;
   8:         ...
   9: 
  10:     public JDBCException(String string, SQLException root) {
  11:         super(string, root);
  12:         ...
  13:     public int getErrorCode() {
  14:         return sqle.getErrorCode();

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     private SQLException sqle;
   7: 
   8:         ...
   9:     public JDBCException(SQLException root) {
  10:         this("SQLException occurred", root);
  11:         ...
  12:     public int getErrorCode() {
  13:         return sqle.getErrorCode();

View Full Code Here
   1: import dataweb.datastore.dbinterface.IConvertException;
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     public boolean isViolationUniqueIndex(SQLException se){
   7:         ...
   8:         return se.getErrorCode()==-9;
   9:     }
  10:         ...
  11:     public String getViolationUniqueIndexName(SQLException se){

View Full Code Here
   1: import java.util.Properties;
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5: 
   6:     public boolean isPasswordFailure(SQLException exception)
   7:     {
   8:         ...
   9:         return exception.getErrorCode()==1017;
  10:     }

View Full Code Here

getNextException

public SQLException getNextException()
Retrieves the exception chained to this SQLException object.
Returns:
the next SQLException object in the chain; null if there are none
Usages and Demos :

View More Examples of getNextException()
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5: 
   6:     public static JDBCException convert(SQLExceptionConverter converter, SQLException sqlException, String message) {
   7:         return convert( converter, sqlException, message, "???" );
   8:         ...
   9:         int errorCode = sqlException.getErrorCode();
  10:         SQLException nested = sqlException.getNextException();
  11:         while ( errorCode == 0 && nested != null ) {
  12:         ...
  13:             errorCode = nested.getErrorCode();
  14:             nested = nested.getNextException();

View Full Code Here
   1: import java.util.Properties;
   2: import java.sql.SQLException;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6:     private void connect() throws SQLException {
   7:         Connection c = DriverManager.getConnection("jdbc:derby:testdb;create=true");
   8:         ...
   9:             c.close();
  10:         } catch (SQLException e) {
  11:         ...
  12:             while (e.getNextException() != null) {

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: import java.util.HashSet;
   4:         ...
   5: 
   6:     public DataAccessException translate(String task, String sql, SQLException sqlEx) {
   7:         if (task == null) {
   8:         ...
   9:         if (sqlState == null) {
  10:             SQLException nestedEx = sqlEx.getNextException();
  11:             if (nestedEx != null) {

View Full Code Here
   1: import java.sql.PreparedStatement;
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:                 connection.setAutoCommit(!inTx);
   6:             } catch (SQLException e) {
   7:                 throw IOExceptionSupport.create(e);
   8:         ...
   9: 
  10:     public void executeBatch() throws SQLException {
  11:         try {
  12:         ...
  13:             log.info("commit failed: "+e.getMessage(), e);
  14:             while( e.getNextException() !=null ) {

View Full Code Here
   1: import java.io.IOException;
   2: import java.sql.SQLException;
   3: import java.util.Collections;
   4:         ...
   5:         }
   6:         catch (SQLException e) {
   7:             JDBCPersistenceAdapter.log("JDBC Failure: ", e);
   8:         ...
   9:             return getAdapter().doGetLastMessageBrokerSequenceId(c);
  10:         } catch (SQLException e) {
  11:             JDBCPersistenceAdapter.log("JDBC Failure: ",e);
  12:         ...
  13:         String s = msg+e.getMessage();
  14:         while( e.getNextException() != null ) {

View Full Code Here

getSQLState

public String getSQLState()
Retrieves the SQLState for this SQLException object.
Returns:
the SQLState value
Usages and Demos :

View More Examples of getSQLState()
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5: 
   6:     private SQLException sqle;
   7:     private String sql;
   8:         ...
   9: 
  10:     public JDBCException(String string, SQLException root) {
  11:         super(string, root);
  12:         ...
  13:     public String getSQLState() {
  14:         return sqle.getSQLState();

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     private SQLException sqle;
   7: 
   8:         ...
   9:     public JDBCException(SQLException root) {
  10:         this("SQLException occurred", root);
  11:         ...
  12:     public String getSQLState() {
  13:         return sqle.getSQLState();

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     public UncategorizedSQLException(String task, String sql, SQLException ex) {
   7:         ...
   8:         super(task + "; uncategorized SQLException for SQL [" + sql + "]; SQL state [" +
   9:         ...
  10:                 ex.getSQLState() + "]; error code [" + ex.getErrorCode() + "]; " + ex.getMessage(), ex);

View Full Code Here
   1: import dataweb.datastore.dbinterface.IConvertException;
   2: import java.sql.SQLException;
   3: 
   4:         ...
   5:     
   6:     public boolean isViolationUniqueIndex(SQLException se){
   7:         ...
   8:         return se.getSQLState().equals("23505");
   9:     }
  10:         ...
  11:     public String getViolationUniqueIndexName(SQLException se){

View Full Code Here
   1:     private int intValue;
   2:     private SQLException exception;
   3:     private ArrayList rows;
   4:         ...
   5:     
   6:     Result(SQLException e) {
   7:         type = EXCEPTION;
   8:         ...
   9:             Collections.sort(rows);
  10:         } catch(SQLException e) {
  11:             type = EXCEPTION;
  12:         ...
  13:             exception.printStackTrace(new PrintWriter(w));
  14:             return "exception: "+exception.getSQLState()+"\n"+w.toString();

View Full Code Here

setNextException

public void setNextException(SQLException ex)
Adds an SQLException object to the end of the chain.
Parameters:
ex - the new exception that will be added to the end of the SQLException chain
Usages and Demos :

View More Examples of setNextException(SQLException ex)
   1:     {
   2:     SQLException original = new SQLException("Original.");
   3:     SQLWarning nestedWarning = new SQLWarning("Nested Warning.");
   4:         ...
   5:     original.setNextException( nestedWarning );
   6:     SqlUtils.toSQLException( original );
   7:     }

View Full Code Here
   1:     synchronized XCachablePreparedStatement take(Connection connection) 
   2:         throws SQLException 
   3:     {
   4:         ...
   5:         } catch(InterruptedException iex) {
   6:             throw new SQLException("Cannot prepare SQL statement in pool");
   7:         }
   8:         ...
   9: 
  10:     synchronized void put(Object reference) throws SQLException {
  11: 
  12:         ...
  13:                 else
  14:                     error.setNextException(ex);

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: import org.apache.derby.iapi.types.SQLBit;
   4:         ...
   5:             throw new java.lang.IllegalArgumentException(
   6:                 SqlException.getMessageUtil().
   7:                     getTextMessage(MessageId.CONN_PRECISION_TOO_LARGE));
   8:         ...
   9: 
  10:     static public void checkForNegativePositiveSqlcard(Sqlca sqlca, Statement statement) throws SqlException {
  11:         if (sqlca != null) {
  12:         ...
  13:         } else {
  14:             accumulatedExceptions.setNextException(latestException);

View Full Code Here
   1: import java.sql.ResultSet;
   2: import java.sql.SQLException;
   3: import java.sql.Statement;
   4:         ...
   5:     public int[] batch(Connection conn, String sql, Object[][] params)
   6:         throws SQLException {
   7: 
   8:         ...
   9: 
  10:         } catch (SQLException e) {
  11:             this.rethrow(e, sql, params);
  12:         ...
  13:                 cause.getErrorCode());
  14:         e.setNextException(cause);

View Full Code Here
   1: 
   2: import java.sql.SQLException;
   3: import java.util.ArrayList;
   4:         ...
   5:     
   6:     public Object getSynchronizationObject() throws SQLException {
   7:         if (coordinator instanceof AutoCommitCoordinator)
   8:         ...
   9:     
  10:     public void executionStarted(AbstractStatement stmt) throws SQLException {
  11:         Object syncObject = getSynchronizationObject();
  12:         ...
  13:                     else
  14:                         resultEx.setNextException(ex);

View Full Code Here