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:com.sun.portal.os.portlets.ChartServlet.java

private JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) {
    JDBCCategoryDataset data = null;//from w w w. j  a  v a2  s .  c  o  m

    try {
        data = new JDBCCategoryDataset(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;
}

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

protected Dataset generatePieDataSet(Connection con, String sql) {
    JDBCPieDataset data = null;/*w  ww. j  a v a 2  s . co m*/

    try {
        data = new JDBCPieDataset(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;
}

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

public void saveOrUpdate(Map<String, Object> map) {

    SqlSession sqlSession = getSession();
    String sql = (String) map.get(KEY_SQL);
    Object[] args = (Object[]) map.get(KEY_ARGS);
    try {// w w w  .j  ava 2  s.c  o  m
        if (log.isDebugEnabled()) {
            log.debug("?(??)=\n" + sql);
        }
        runner.update(sqlSession.getConnection(), sql, args);
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory());
    }
}

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

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

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

From source file:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java

public void add(SpoBinaryDTO dto) throws DAOException {

    if (dto == null) {
        throw new IllegalArgumentException("DTO object must not be null");
    }/*from   w  w  w  .j a  va  2  s  . c o m*/

    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = getSQLConnection();
        stmt = conn.prepareStatement(SQL_ADD);

        stmt.setLong(1, dto.getSubjectHash());

        String lang = dto.getLanguage();
        stmt.setString(2, lang == null ? "" : lang);

        String contentType = dto.getContentType();
        stmt.setString(3, contentType == null ? "" : contentType);

        stmt.setString(4, dto.isMustEmbed() ? "Y" : "N");

        stmt.executeUpdate();
    } catch (SQLException sqle) {
        throw new DAOException(sqle.getMessage(), sqle);
    } finally {
        SQLUtil.close(stmt);
        SQLUtil.close(conn);
    }
}

From source file:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java

public SpoBinaryDTO get(String subjectUri) throws DAOException {

    if (StringUtils.isBlank(subjectUri)) {
        throw new IllegalArgumentException("Subject uri must not be blank");
    }/*from   w  w w .java2s. c om*/

    ResultSet rs = null;
    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = getSQLConnection();
        stmt = conn.prepareStatement(SQL_GET);
        stmt.setLong(1, Hashes.spoHash(subjectUri));
        rs = stmt.executeQuery();
        if (rs != null && rs.next()) {

            SpoBinaryDTO dto = new SpoBinaryDTO(rs.getLong("SUBJECT"));
            dto.setContentType(rs.getString("DATATYPE"));
            dto.setLanguage(rs.getString("OBJ_LANG"));
            dto.setMustEmbed(YesNoBoolean.parse(rs.getString("MUST_EMBED")));

            return dto;
        }
    } catch (SQLException e) {
        throw new DAOException(e.getMessage(), e);
    } finally {
        SQLUtil.close(rs);
        SQLUtil.close(stmt);
        SQLUtil.close(conn);
    }

    return null;
}

From source file:fitmon.WorkoutData.java

public void addData(String workout, String intensity, int minutes, double calories, String date, int userId)
        throws IOException, NoSuchAlgorithmException, InvalidKeyException, JSONException, SQLException,
        ClassNotFoundException {//from   ww w  . ja v  a2 s .  c o m

    //ArrayList arr = new ArrayList(al);
    PreparedStatement st = null;
    Connection conn = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/fitmon", "root",
                "april-23");
        String query = "INSERT into workout (type,calories,date,intensity,duration,userId) values (?,?,?,?,?,?);";
        st = conn.prepareStatement(query);
        conn.setAutoCommit(false);

        //st.setInt(1,7);
        st.setString(1, workout);
        st.setDouble(2, calories);
        st.setString(3, date);
        st.setString(4, intensity);
        st.setInt(5, minutes);
        st.setInt(6, userId);
        st.addBatch();
        st.executeBatch();

        conn.commit();
        System.out.println("Record is inserted into workout table!");

        st.close();
        conn.close();

    } catch (SQLException e) {

        System.out.println(e.getMessage());
        conn.rollback();
    } finally {

        if (st != null) {
            st.close();
        }

        if (conn != null) {
            conn.close();
        }

    }

}

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

/**
 * /*from  ww  w  .  j av a 2  s. com*/
 * @param column ?
 * @param sql sql?
 * @param params ?
 * @return 
 */
public Object query(int column, String sql, Object... params) {

    SqlSession sqlSession = getSession();
    Object result;
    try {
        if (log.isDebugEnabled()) {
            log.debug("??=\n" + sql);
        }
        result = runner.query(sqlSession.getConnection(), sql, new ScalarHandler(column), params);
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        SqlSessionUtils.closeSqlSession(sqlSession, getSqlSessionFactory());
    }
    return result;
}

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

public UtenteModel getUtenteSmartphone(String email) {

    SmartphoneModel smartphoneModel = new SmartphoneModel();

    UtenteModel utenteModel = new UtenteModel();

    MysqlDataSource dataSource = new MysqlDataSource();

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

    Connection conn = null;/*from  ww w . j  a v  a 2s . c  o m*/

    try {

        conn = dataSource.getConnection();

        PreparedStatement stmtUserInfo = conn.prepareStatement(USER_SMARTH_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"));
            smartphoneModel.setMarca(rsUserInfoSet.getString("marca"));
            smartphoneModel.setModello(rsUserInfoSet.getString("modello"));
            utenteModel.setSmartphone(smartphoneModel);
        }

    } 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:eionet.cr.dao.virtuoso.VirtuosoSpoBinaryDAO.java

@Override
public void delete(List<String> subjectUris) throws DAOException {

    // make sure the list is not null or empty
    if (subjectUris == null || subjectUris.isEmpty()) {
        return;//from  ww w .ja va 2s.co m
    }

    // convert URIs to hashes
    ArrayList<Long> hashes = new ArrayList<Long>();
    for (String uri : subjectUris) {
        hashes.add(Long.valueOf(Hashes.spoHash(uri)));
    }

    // prepare connection and the hashes comma-separated
    Connection conn = null;
    String hashesStr = "(" + Util.toCSV(hashes) + ")";

    try {
        // do it in a transaction
        conn = getSQLConnection();
        conn.setAutoCommit(false);

        // delete references from SPO_BINARY
        SQLUtil.executeUpdate("delete from SPO_BINARY where SUBJECT in " + hashesStr, conn);

        // commit the transaction
        conn.commit();
    } catch (SQLException e) {
        throw new DAOException(e.getMessage(), e);
    } finally {
        SQLUtil.rollback(conn);
        SQLUtil.close(conn);
    }
}