Code example for Connection

Methods: createStatementisClosed

0
     * @return 
     * @throws LoggerException 
     */ 
    public static boolean IpExist(Connection c, String ipAddress) throws LoggerException {
        try { 
            if (c == null || c.isClosed()) {
                throw new LoggerException("Database null or closed"); 
            } 
            String sqlRequest = "SELECT count(*) from " + TABLE_NAME + " where  " + IP_ADDRESS + "='" + ipAddress + "' ;";
            Statement st = c.createStatement();
            ResultSet res = st.executeQuery(sqlRequest);
            res.next();
            if (res.getInt(1) == 0) {
                return false; 
            } else if (res.getInt(1) > 0) {
                return true; 
            } 
        } catch (SQLException e) {
            throw new LoggerException("IPcompanyTable: IpExist ( Connection c , String ipAddress   ) problem : (" + e.getErrorCode() + " )" + e.getMessage());
        }