Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.neo4j.jdbc.http.driver.Neo4jResponse.java

/**
 * Transform the error list to a string for display purpose.
 *
 * @return A String with all errors//from www .  ja va2  s . c o m
 */
public String displayErrors() {
    StringBuilder sb = new StringBuilder();
    if (hasErrors()) {
        sb.append("Some errors occurred : \n");
        for (SQLException error : errors) {
            sb.append("[").append(error.getSQLState()).append("]").append(":").append(error.getMessage())
                    .append("\n");
        }
    }
    return sb.toString();
}

From source file:gov.nih.nci.cacisweb.dao.virtuoso.VirtuosoCommonUtilityDAO.java

/**
 * This method wraps the exceptions and throws a single exception, to be handled by the calling object.
 * /*from ww w .j a  v  a 2 s.c om*/
 * @throws DBUnavailableException
 */
private void openCaCISConnection() throws DBUnavailableException {
    try {
        // DataSource dataSource = ServiceLocator.getInstance().getDataSourceByName(virtuosoDataSourceString);
        // cacisConnection = dataSource.getConnection();

        String driverName = CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_DATABASE_VIRTUOSO_DRIVER);
        Class.forName(driverName);

        // Create a connection to the database
        cacisConnection = DriverManager.getConnection(
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_DATABASE_VIRTUOSO_URL),
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_DATABASE_VIRTUOSO_USERNAME),
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_DATABASE_VIRTUOSO_PASSWORD));
    } catch (SQLException sqle) {
        log.error(sqle.getMessage());
        throw new DBUnavailableException(sqle.getMessage());
        // } catch (ServiceLocatorException sle) {
        // log.error(sle.getMessage());
        // throw new DBUnavailableException(sle.getMessage());
    } catch (ClassNotFoundException e) {
        log.error(e.getMessage());
        throw new DBUnavailableException(e.getMessage());
    } catch (CaCISWebException e) {
        log.error(e.getMessage());
        throw new DBUnavailableException(e.getMessage());
    }
}

From source file:de.highbyte_le.weberknecht.db.DefaultWebDbConnectionProvider2.java

@Override
public Connection getConnection() throws DBConnectionException {
    try {/*from  ww w  .  j  av  a 2  s.  com*/

        if (!isAvailable())
            throw new DBConnectionException("db connection is not available (e.g. not configured)");

        Connection con = null;
        boolean ok = false;
        int count = 0;
        while (!ok && count < onErrorRetryCount) {
            count++;
            con = this.datasource.getConnection();

            try {
                Statement st = con.createStatement();
                ResultSet rs = st.executeQuery("select true");
                if (rs.next())
                    ok = true;
            } catch (SQLException e) {
                log.warn("SQL exception while testing connection (attempt " + count + "): " + e.getMessage());
                try {
                    con.close();
                } catch (SQLException e1) {
                    /**/}
                //and again
            }
        }

        return con;

    } catch (SQLException e) {
        log.error("getConnection() - SQLException: " + e.getMessage(), e);
        throw new DBConnectionException("sql exception: " + e.getMessage());
    }
}

From source file:br.com.great.dao.TextosDAO.java

/**
* 
* Mtodo responsvel por get os dados da CTextos no banco de dados
*
* @author Carleandro Noleto/*from w  ww . ja va2 s  .com*/
 * @param mecanica_id int
 * @return JSONObject Dados de CTextos
* @since 19/01/2015
* @version 1.0
*/
public Texto getMecCTextos(int mecanica_id) {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Connection conexao = criarConexao();
    Texto cTextos = null;
    try {
        String sql = "SELECT * FROM  `ctextos` WHERE  `ctextos`.`mecsimples_id` =  " + mecanica_id;
        pstmt = conexao.prepareStatement(sql);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            cTextos = new Texto();
            cTextos.setTexto_id(rs.getInt("id"));
            cTextos.setTexto(rs.getString("texto"));
            cTextos.setCapturarObjeto(new CapturarObjeto());
            cTextos.getCapturarObjeto().setJogador_id(rs.getInt("jogador_id"));
            cTextos.getCapturarObjeto()
                    .setPosicao(new Posicao(rs.getDouble("latitude"), rs.getDouble("longitude")));
            cTextos.setMecsimples_id(rs.getInt("mecsimples_id"));
        }
    } catch (SQLException e) {
        System.out.println("Erro ao listar dados de uma mecanica cTextos: " + e.getMessage());
    } finally {
        fecharConexao(conexao, pstmt, rs);
    }
    return cTextos;

}

From source file:com.mycompany.rubricatelefonica.DefaultUtenteDao.java

public boolean insertNewUtente(UtenteModel utente) {
    boolean inserito = false;
    MysqlDataSource dataSource = new MysqlDataSource();

    dataSource.setUser("root");
    dataSource.setPassword("root");
    dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef");

    Connection conn = null;//from   w w  w  .  j  ava2s.  c o  m

    try {

        conn = dataSource.getConnection();

        PreparedStatement stmtInsertUtente = conn.prepareStatement(INSERT_UTENTE);
        stmtInsertUtente.setInt(1, utente.getId());
        stmtInsertUtente.setString(2, utente.getImei());
        stmtInsertUtente.setString(3, utente.getNome());
        stmtInsertUtente.setString(4, utente.getCognome());
        stmtInsertUtente.setString(5, utente.getEmail());
        stmtInsertUtente.setString(6, utente.getNumCell());
        stmtInsertUtente.setString(7, utente.getNumTelFisso());
        stmtInsertUtente.setString(8, utente.getData());

        if (stmtInsertUtente.executeUpdate() > 0) {
            inserito = true;
        }
    } catch (SQLException e) {
        System.out.println(e.getMessage());
        System.out.println("errore!! Connessione Fallita");
    } finally {

        DbUtils.closeQuietly(conn); //oppure try with resource
    }

    //
    return inserito;
}

From source file:database.DataBaseMySQL.java

public ResultSet get(String quary) {

    ResultSet res;//from w w  w  . j  a v a 2  s .c o  m
    Statement stmt;

    try {

        stmt = conn.createStatement();
        res = stmt.executeQuery(quary);

        return res;

        // Now do something with the ResultSet ....
    } catch (SQLException ex) {
        // handle any errors
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }

    return res = null;

}

From source file:com.mycompany.rubricatelefonica.DefaultUtenteDao.java

public UtenteModel getUtenteInfo(String email) {

    UtenteModel utenteModel = new UtenteModel();

    MysqlDataSource dataSource = new MysqlDataSource();

    dataSource.setUser("root");
    dataSource.setPassword("root");
    dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef");

    Connection conn = null;//  w  w  w  . j a  v  a2  s  .co m

    try {

        conn = dataSource.getConnection();

        PreparedStatement stmtUserInfo = conn.prepareStatement(USER_INFO);

        stmtUserInfo.setString(1, email);

        ResultSet rsUserInfoSet = stmtUserInfo.executeQuery();

        if (rsUserInfoSet.first()) {

            utenteModel.setNome(rsUserInfoSet.getString("nome"));
            utenteModel.setCognome(rsUserInfoSet.getString("cognome"));
            utenteModel.setEmail(rsUserInfoSet.getString("email"));
            utenteModel.setNumCell(rsUserInfoSet.getString("numCell"));
        }

    } catch (SQLException e) {
        System.out.println(e.getMessage());
        System.out.println("errore!! Connessione Fallita");
    } finally {

        DbUtils.closeQuietly(conn); //oppure try with resource
    }

    return utenteModel;
}

From source file:ipstore.db.ServerBean.java

public void destroy() {

    logger.info("HSQL Server Shutdown sequence initiated");
    if (dataSource != null) {
        Connection con = null;//from   ww  w  . j  av a 2 s . co  m
        try {
            con = dataSource.getConnection();
            con.createStatement().execute("SHUTDOWN");
        } catch (SQLException e) {
            logger.error("HSQL Server Shutdown failed: " + e.getMessage());
        } finally {
            try {
                if (con != null)
                    con.close();
            } catch (Exception ignore) {
            }
        }
    } else {
        logger.warn("HSQL ServerBean needs a dataSource property set to shutdown database safely.");
    }
    server.signalCloseAllServerConnections();
    int status = server.stop();
    long timeout = System.currentTimeMillis() + 5000;
    while (status != ServerConstants.SERVER_STATE_SHUTDOWN && System.currentTimeMillis() < timeout) {
        try {
            Thread.sleep(100);
            status = server.getState();
        } catch (InterruptedException e) {
            logger.error("Error while shutting down HSQL Server: " + e.getMessage());
            break;
        }
    }
    if (status != ServerConstants.SERVER_STATE_SHUTDOWN) {
        logger.warn("HSQL Server failed to shutdown properly.");
    } else {
        logger.info("HSQL Server Shutdown completed");
    }
    server = null;

}

From source file:com.qcloud.component.snaker.access.mybatis.MybatisAccess.java

public <T> List<T> queryList(Class<T> clazz, String sql, Object... args) {

    SqlSession sqlSession = getSession();
    try {/*from ww w . j ava 2 s  . co m*/
        if (log.isDebugEnabled()) {
            log.debug("?=\n" + sql);
        }
        return runner.query(sqlSession.getConnection(), sql, new BeanPropertyHandler<T>(clazz), args);
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new SnakerException(e.getMessage(), e.getCause());
    } finally {
        SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory());
    }
}

From source file:com.sun.portal.os.portlets.ChartServlet.java

private JDBCXYDataset generateXYDataSet(Connection con, String sql) {
    JDBCXYDataset data = null;//from www.  j  a  v a  2 s. c om

    try {
        data = new JDBCXYDataset(con);
        data.executeQuery(sql);
        con.close();
    } catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
    }
    return data;
}