Example usage for java.sql SQLException getErrorCode

List of usage examples for java.sql SQLException getErrorCode

Introduction

In this page you can find the example usage for java.sql SQLException getErrorCode.

Prototype

public int getErrorCode() 

Source Link

Document

Retrieves the vendor-specific exception code for this SQLException object.

Usage

From source file:TaskManager.java

public static String readException(SQLException sqlX) {
    StringBuffer msg = new StringBuffer(1024);
    SQLException nextX;/*w  w w.  j  a  va2  s .c o  m*/
    int exceptionNumber = 0;

    do {
        ++exceptionNumber;

        msg.append("Exception " + exceptionNumber + ": \n");
        msg.append("  Message: " + sqlX.getMessage() + "\n");
        msg.append("  State  : " + sqlX.getSQLState() + "\n");
        msg.append("  Code   : " + sqlX.getErrorCode() + "\n");
    } while ((nextX = sqlX.getNextException()) != null);

    return (msg.toString());
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java

public static void setPath(Connection conn, String schemaName) {

    if (schemaName != null && schemaName.length() > 0) {
        try {/*from w  w w .  j a va 2  s .com*/

            // set even the CURRENT PATH... this is for UDF's
            SQLExecutor.executeUpdate(conn, "set current path = " + schemaName + ",current path");
        } catch (SQLExceptionWrapper e) {
            SQLException e1 = (SQLException) e.getCause();
            if (e1.getErrorCode() == -585) {
                // duplicate schema, no action required
                return;
            }
            throw new RdfStoreException(e1.getLocalizedMessage(), e1);
        }

    }
}

From source file:com.xqdev.sql.MLSQL.java

private static void addExceptions(Element meta, SQLException e) {
    if (e == null)
        return;/*from w w w. java 2 s.  c om*/

    Namespace sql = meta.getNamespace();
    Element exceptions = new Element("exceptions", sql);
    meta.addContent(exceptions);
    do {
        exceptions.addContent(new Element("exception", sql).setAttribute("type", e.getClass().getName())
                .addContent(new Element("reason", sql).setText(e.getMessage()))
                .addContent(new Element("sql-state", sql).setText(e.getSQLState()))
                .addContent(new Element("vendor-code", sql).setText("" + e.getErrorCode())));
        e = e.getNextException();
    } while (e != null);
}

From source file:net.chrisrichardson.foodToGo.util.spring.MyOracleSQLExceptionTranslator.java

protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) {
    switch (sqlex.getErrorCode()) {
    case 8177:/* ww  w. j  a  v a 2 s .  com*/
        return new CannotSerializeTransactionException("Can't serialize", sqlex);
    case 60:
        return new CannotAcquireLockException("Deadlock", sqlex);
    default:
        return null;
    }
}

From source file:de.unibremen.informatik.tdki.combo.data.JdbcTemplate.java

public void execute(String query) {
    try {/*from   w  w  w  .  j  a  va  2  s .c  o m*/
        qRunner.update(connection, query);
    } catch (SQLException ex) {
        if (ex.getErrorCode() == -204) {
            throw new DBObjectDoesNotExistException(ex);
        } else {
            throw new RuntimeException(ex);
        }
    }
}

From source file:de.unibremen.informatik.tdki.combo.data.JdbcTemplate.java

public List queryForList(String query, final Class elementType) {
    try {/* ww  w. ja  v  a2 s  . co  m*/
        return qRunner.query(connection, query, new AbstractListHandler<Object>() {

            @Override
            protected Object handleRow(ResultSet rs) throws SQLException {
                return rs.getObject(1, elementType);
            }

        });
    } catch (SQLException ex) {
        if (ex.getErrorCode() == -204) {
            throw new DBObjectDoesNotExistException(ex);
        } else {
            throw new RuntimeException(ex);
        }
    }
}

From source file:com.pontecultural.flashcards.WebServicesController.java

/**
 * Fetch cards for deck. /*from   w  ww. j  a va  2s.c o  m*/
 */
@RequestMapping(value = "/deckId/{deckId}/cards.json", method = RequestMethod.GET)
public String getCards(HttpServletRequest req, @PathVariable Integer deckId, Model model) {
    logger.info("get cards for deck: " + deckId);
    try {
        model.addAttribute("flashcards", jdbcFlashcardsDao.fetchCardsByDeck(deckId));
    } catch (DataAccessException e) {
        SQLException sqle = (SQLException) e.getCause();
        logger.error("Error code: " + sqle.getErrorCode());
        logger.error("SQL state: " + sqle.getSQLState());
        logger.error("Error msg: " + sqle.getMessage());
        model.addAttribute("flashcards", null);
    }
    return "flashcardstemplate"; // was  "observationtemplate" - do I need to configure this someone? 
}

From source file:HelloMySQLJDBC.java

private void displaySQLErrors(SQLException e) {
    System.out.println("SQLException: " + e.getMessage());
    System.out.println("SQLState:     " + e.getSQLState());
    System.out.println("VendorError:  " + e.getErrorCode());
}

From source file:com.nabla.wapp.server.dispatch.DispatchService.java

private <A extends IAction<R>, R extends IResult> R dispatch(A action, final UserSession session)
        throws DispatchException {
    if (log.isTraceEnabled())
        log.trace("handling command '" + action.getClass().getSimpleName() + "'");
    IActionHandler<A, R> handler = handlers.findHandler(action);
    if (handler == null)
        throw new UnsupportedActionException(action);
    try {//from w  w w  .j  a v  a 2s  .  c om
        final IUserSessionContext ctx = ctxFactory.get(session, handler.requireWriteContext());
        try {
            return handler.execute(action, ctx);
        } finally {
            ctx.close();
        }
    } catch (final SQLException e) {
        if (log.isErrorEnabled())
            log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e);
        throw new InternalErrorException(Util.formatInternalErrorDescription(e));
    } catch (DispatchException e) {
        if (log.isErrorEnabled())
            log.error("internal error", e);
        throw e;
    } catch (Throwable e) {
        if (log.isErrorEnabled())
            log.error("internal error", e);
        throw new InternalErrorException(Util.formatInternalErrorDescription(e));
    }
}

From source file:com.nabla.wapp.server.auth.LoginUserService.java

@Override
public String execute(String userName, String password, String locale) {
    final ValidationException errors = new ValidationException();
    try {/*w  w w.j  a va2 s.c  o m*/
        IUser.NAME_CONSTRAINT.validate(IUser.NAME, userName, errors, ValidatorContext.ADD);
        IUser.PASSWORD_CONSTRAINT.validate(IUser.PASSWORD, password, errors, ValidatorContext.ADD);
    } catch (DispatchException __) {
    }
    if (errors.isEmpty()) {
        try {
            final Connection conn = db.getConnection();
            try {
                final UserManager userManager = new UserManager(conn);
                final Integer userId = userManager.isValidSession(userName, password);
                if (userId != null) {
                    userManager.onUserLogged(userId);
                    return UserSession.save(this.getThreadLocalRequest(), userId, userName, locale);
                }
            } finally {
                Database.close(conn);
            }
        } catch (final SQLException e) {
            if (log.isErrorEnabled())
                log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e);
        }
    }
    return null;
}