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:com.tg.webservice.controller.UsuarioController.java

private int registerUser(String name, String uname) {
    System.out.println("Inside checkCredentials");
    int result = 3;
    if (StringUtils.isNotBlank(uname)) {
        try {/*  w  w w . ja v  a  2 s  .  c  o  m*/
            if (!checkCredentials(uname))
                if (UsuarioDao.insertUser(name, uname)) {
                    System.out.println("RegisterUSer if");
                    result = 0;
                }
        } catch (SQLException sqle) {
            System.out.println("RegisterUSer catch sqle");
            if (sqle.getErrorCode() == 1062) {
                result = 1;
            } else if (sqle.getErrorCode() == 1064) {
                System.out.println(sqle.getErrorCode());
                result = 2;
            }
        } catch (Exception e) {
            System.out.println("Inside checkCredentials catch e ");
            result = 3;
        }
    } else {
        System.out.println("Inside checkCredentials else");
        result = 3;
    }

    return result;
}

From source file:com.viettel.logistic.wms.dao.CellsDAO.java

/**
 * NgocND6 insert list cell using import excel
 * @param lstCell//from   w  w  w . ja v  a 2 s .  co  m
 * @param stockID
 * @return 
 */
public ResultDTO insertListCells(List<Cells> lstCell, String stockID) {
    Session openSession;
    openSession = sessionFactory.openSession();
    Transaction tx = openSession.beginTransaction();
    ResultDTO result = new ResultDTO();
    Cells cells = null;
    String lstCellsId = "";
    try {
        for (int i = 0; i < lstCell.size(); i++) {
            cells = lstCell.get(i);
            lstCellsId = lstCellsId + "," + cells.getCode();
            openSession.save(cells);
            if (i % 50 == 0) { // Same as the JDBC batch size
                //flush a batch of inserts and release memory:
                openSession.flush();
                openSession.clear();
                lstCellsId = "";
            }
        }
        tx.commit();
        result.setMessage(ParamUtils.SUCCESS);
    } catch (HibernateException ex) {

        if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
            SQLException se = (SQLException) ex.getCause();
            if (se.getErrorCode() == 1) {
                openSession.clear();
                ConditionBean condition = new ConditionBean("code", ParamUtils.OP_IN,
                        lstCellsId.replaceFirst(",", ""), ParamUtils.TYPE_STRING);
                ConditionBean condition1 = new ConditionBean("stockId", ParamUtils.OP_EQUAL,
                        String.valueOf(stockID), ParamUtils.TYPE_NUMBER);
                List<ConditionBean> lstConditionBeans = new ArrayList<>();
                lstConditionBeans.add(condition);
                lstConditionBeans.add(condition1);
                List<Cells> lstCellsViolated = findSession("Cells", lstConditionBeans, "code", 0,
                        Integer.MAX_VALUE, null, getSession());
                if (lstCellsViolated != null && !lstCellsViolated.isEmpty()) {
                    String id = "";
                    for (Cells item : lstCellsViolated) {
                        id = id + "," + item.getCode();
                    }
                    result.setKey(id.replaceFirst(",", ""));
                }
            }
        }
        tx.rollback();
        result.setMessage(ParamUtils.FAIL);
    } finally {
        openSession.close();
    }

    return result;
}

From source file:com.nabla.dc.server.ImageService.java

@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String imageId = request.getParameter("id");
    if (imageId == null || imageId.isEmpty()) {
        if (log.isTraceEnabled())
            log.trace("missing image ID");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {/*from  w  w  w  .  j  a va2 s. co  m*/
        try {
            if (exportImage(imageId, response)) {
                //   response.setStatus(HttpServletResponse.SC_OK);
            } else
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (final SQLException e) {
            if (log.isErrorEnabled())
                log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (final Throwable e) {
            if (log.isErrorEnabled())
                log.error("unexpected error", e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:com.jedi.oracle.OracleCall.java

private boolean reExecutionRequired(SQLException e) {
    return "72000".equals(e.getSQLState()) && e.getErrorCode() == 4068;
}

From source file:com.ironiacorp.persistence.hibernate.GenericHibernateDataSource.java

/**
 * Handles an specific MySQL error./*from   w  ww  . j  a  va  2  s.com*/
 * 
 * @param sqle The SQLException to be analysed.
 * 
 * @return The exception (if the error is unrecoverable) or null if the
 * problem was solved (or simply ignored).
 */
public Exception handleMySQLError(SQLException sqle) {
    switch (sqle.getErrorCode()) {
    case 1146:
        log.debug("Ignoring error", sqle);
        sqle = null;
        break;
    default:
        log.debug("Cannot recover from error", sqle);
    }
    return sqle;
}

From source file:com.espertech.esper.epl.db.DatabaseDSFactoryConnFactory.java

public Connection getConnection() throws DatabaseConfigException {
    Connection connection;// ww w  .j  av a  2  s .c o m
    try {
        connection = dataSource.getConnection();
    } catch (SQLException ex) {
        String detail = "SQLException: " + ex.getMessage() + " SQLState: " + ex.getSQLState() + " VendorError: "
                + ex.getErrorCode();

        throw new DatabaseConfigException(
                "Error obtaining database connection using datasource " + "with detail " + detail, ex);
    }

    DatabaseDMConnFactory.setConnectionOptions(connection, connectionSettings);

    return connection;
}

From source file:com.nabla.wapp.server.basic.general.ExportService.java

@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String id = request.getParameter("id");
    if (id == null || id.isEmpty()) {
        if (log.isTraceEnabled())
            log.trace("missing file ID");
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;/*w  w  w .j a v  a 2  s  .c om*/
    }
    final UserSession userSession = UserSession.load(request);
    if (userSession == null) {
        if (log.isTraceEnabled())
            log.trace("missing user session");
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    try {
        if (exportFile(id, userSession, response)) {
            //   response.setStatus(HttpServletResponse.SC_OK);
        } else
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (final SQLException e) {
        if (log.isErrorEnabled())
            log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (final Throwable e) {
        if (log.isErrorEnabled())
            log.error("unexpected error", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:net.firejack.platform.core.config.upgrader.SchemaUpgrader.java

/**
 * This method returns current package version by package lookup
 *
 * @param packageLookup/*from  w  w  w.  j a v  a  2s.c  o  m*/
 * @return version
 */
private Version getDatabaseVersion(String packageLookup) {
    try {
        Connection connection = dataSource.getConnection();
        try {
            connection.setAutoCommit(true);

            PreparedStatement statement = connection.prepareStatement("SELECT database_version "
                    + "FROM opf_registry_node " + "WHERE lookup = '" + packageLookup + "'");
            try {
                ResultSet resultSet = statement.executeQuery();
                try {
                    if (resultSet.next())
                        return new Version(resultSet.getInt(1));
                    else
                        throw new BusinessFunctionException("Can't find database version number.");
                } finally {
                    JdbcUtils.closeResultSet(resultSet);
                }
            } catch (SQLException e) {
                if (1054 == e.getErrorCode()) {
                    return new Version(1);
                }
                throw new RuntimeException(e);
            } finally {
                JdbcUtils.closeStatement(statement);
            }
        } finally {
            connection.setAutoCommit(false);
            JdbcUtils.closeConnection(connection);
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.btmatthews.maven.plugins.inmemdb.db.derby.DerbyDatabase.java

/**
 * Shutdown the in-memory Apache Derby database by opening a connection with
 * <code>drop=true</code>. If successful this will cause a SQL exception
 * with a SQL State of 08006 and a vendor specific error code of 45000.
 *
 * @param logger Used to report errors and raise exceptions.
 *///from  ww  w.  j  av  a2s. c o  m
@Override
public void stop(final Logger logger) {

    logger.logInfo("Stopping embedded Derby database");

    if (server != null) {
        final Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(DROP, TRUE);
        try {
            DriverManager.getConnection(getUrl(attributes), getUsername(),
                    getPassword().length() == 0 ? null : getPassword());
        } catch (final SQLException exception) {
            if (exception.getErrorCode() != 45000 || !"08006".equals(exception.getSQLState())) {
                final String message = MessageUtil.getMessage(ERROR_STARTING_SERVER, getDatabaseName());
                logger.logError(message, exception);
                return;
            }
        }
        try {
            server.shutdown();
        } catch (final Exception exception) {
            final String message = MessageUtil.getMessage(ERROR_STOPPING_SERVER, getDatabaseName());
            logger.logError(message, exception);
            return;
        }
    }

    logger.logInfo("Stopped embedded Derby database");
}

From source file:it.grid.storm.persistence.util.db.DBConnectionPool.java

private void handleSQLException(SQLException e) throws PersistenceException {

    log.error("SQL Error: {}, SQLState: {}, VendorError: {}.", e.getMessage(), e.getSQLState(),
            e.getErrorCode(), e);

    throw new PersistenceException(e);

}