List of usage examples for org.apache.commons.dbutils BeanProcessor toBean
public <T> T toBean(ResultSet rs, Class<T> type) throws SQLException
ResultSet
row into a JavaBean. From source file:ke.co.tawi.babblesms.server.persistence.geolocation.CountryDAO.java
/** * *//* www . j a va 2s . co m*/ @Override public Country getCountry(String uuid) { Country network = null; Connection conn = null; PreparedStatement pstmt = null; ResultSet rset = null; BeanProcessor b = new BeanProcessor(); try { conn = dbCredentials.getConnection(); pstmt = conn.prepareStatement("SELECT * FROM Country WHERE Uuid = ?;"); pstmt.setString(1, uuid); rset = pstmt.executeQuery(); if (rset.next()) { network = b.toBean(rset, Country.class); } } catch (SQLException e) { logger.error("SQL Exception when getting network with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } return network; }
From source file:ke.co.tawi.babblesms.server.persistence.geolocation.CountryDAO.java
/** * * @param name/*from www. j av a2 s . co m*/ * @return network * Returns * */ @Override public Country getCountryByName(String name) { Country network = null; Connection conn = null; PreparedStatement pstmt = null; ResultSet rset = null; BeanProcessor b = new BeanProcessor(); try { conn = dbCredentials.getConnection(); pstmt = conn.prepareStatement("SELECT * FROM Country WHERE LOWER(name) like LOWER(?);"); pstmt.setString(1, "%" + name + "%"); rset = pstmt.executeQuery(); if (rset.next()) { network = b.toBean(rset, Country.class); } } catch (SQLException e) { logger.error("SQL Exception when getting network with uuid: " + name); logger.error(ExceptionUtils.getStackTrace(e)); } return network; }
From source file:ke.co.tawi.babblesms.server.persistence.template.MessageTemplateDAO.java
/** * *//* w w w.jav a 2 s . c o m*/ @Override public MessageTemplate getTemplate(String uuid) { MessageTemplate messageTemplate = null; BeanProcessor b = new BeanProcessor(); try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE Uuid = ?;");) { pstmt.setString(1, uuid); try (ResultSet rset = pstmt.executeQuery();) { if (rset.next()) { messageTemplate = b.toBean(rset, MessageTemplate.class); } } } catch (SQLException e) { logger.error("SQL Exception when getting messageTemplate with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } return messageTemplate; }
From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java
/** * *//*from w w w . ja va 2 s. co m*/ @Override public MessageTemplate getMessageTemplate(String uuid) { MessageTemplate messageTemplate = null; Connection conn = null; PreparedStatement pstmt = null; ResultSet rset = null; BeanProcessor b = new BeanProcessor(); try { conn = dbCredentials.getConnection(); pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE Uuid = ?;"); pstmt.setString(1, uuid); rset = pstmt.executeQuery(); if (rset.next()) { messageTemplate = b.toBean(rset, MessageTemplate.class); } } catch (SQLException e) { logger.error("SQL Exception when getting messageTemplate with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } finally { if (rset != null) { try { rset.close(); } catch (SQLException e) { } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } return messageTemplate; }
From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java
/** * *///from w w w .j a v a 2s . co m @Override public MessageTemplate titleexists(String title) { MessageTemplate messageTemplate = null; Connection conn = null; PreparedStatement pstmt = null; ResultSet rset = null; BeanProcessor b = new BeanProcessor(); try { conn = dbCredentials.getConnection(); pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE title = ?;"); pstmt.setString(1, title); rset = pstmt.executeQuery(); if (rset.next()) { messageTemplate = b.toBean(rset, MessageTemplate.class); } } catch (SQLException e) { logger.error("SQL Exception when getting messageTemplate with uuid: " + title); logger.error(ExceptionUtils.getStackTrace(e)); } finally { if (rset != null) { try { rset.close(); } catch (SQLException e) { } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } return messageTemplate; }
From source file:ke.co.tawi.babblesms.server.persistence.notification.NotificationDAO.java
/** */*from w w w . j a v a 2 s . c om*/ */ @Override public Notification getNotification(String uuid) { Notification notification = null; Connection conn = null; PreparedStatement pstmt = null; ResultSet rset = null; BeanProcessor b = new BeanProcessor(); try { conn = dbCredentials.getConnection(); pstmt = conn.prepareStatement("SELECT * FROM notification WHERE Uuid = ?;"); pstmt.setString(1, uuid); rset = pstmt.executeQuery(); if (rset.next()) { notification = b.toBean(rset, Notification.class); } } catch (SQLException e) { logger.error("SQL Exception when getting network with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } finally { if (rset != null) { try { rset.close(); } catch (SQLException e) { } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } return notification; }
From source file:wzw.sql.ResultSetConverter.java
/** * Convert a ResultSet Object to Bean./*from w w w. java 2 s .c o m*/ * @param rs * @param type * @return * @throws SQLException */ public static Object toBean(ResultSet rs, Class<?> type) throws SQLException { BeanProcessor bp = new BeanProcessor(); return bp.toBean(rs, type); }