2011년 11월 29일 화요일

linux 관련

CentOS release 5.5 (Final)

설치 방법
http://blog.daum.net/kimuks/7531860

mysql 설치법
http://blog.naver.com/PostView.nhn?blogId=seban21&logNo=70105302948

2011년 11월 27일 일요일

html css 관련 링크

 css div 래이아웃 샘플
http://coding.smashingmagazine.com/2007/01/12/free-css-layouts-and-templates/

2011년 11월 22일 화요일

google analytics 외부 클릭 집계 모듈 설치

소스

        if("2".equals(TYPE)) {
                result = "<a href=\""+ LINK_SRC + "\" target=\"_blank\" onClick=\"recordOutboundLink(this, '" + ID + "','" + NAME + "'" + ");return false;\">" + TEXT + "</a>";
            // banner
            } else {
                result = "<a href=\""+ LINK_SRC + "\" target=\"_blank\" onClick=\"recordOutboundLink(this, '" + ID + "','" + NAME + "'" + ");return false;\"><img src=\"" + IMG_SRC + "\"></a>";
            }


여기에서 ID 와 네임은( 카테고리, 엑션 ) 추후에 google analytics 에서 보기 쉽게하기위해 설정



구글 설치(해더 이거나 아니거나 상간업음)
 <script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-26953161-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

function recordOutboundLink(link, category, action) {
  try {
    var myTracker=_gat._getTrackerByName();
    _gaq.push(['_trackEvent', category , action]);
    if (link.target == '_blank') {
        window.open(link.href);
    } else {
        setTimeout('document.location = "' + link.href + '"', 100)
    }
  }catch(err){}
}
</script>


http://www.google.com/support/googleanalytics/bin/answer.py?answer=55527&hl=ko

2011년 9월 1일 목요일

java ssl 증명서 없는 rss 가지고 오기.

import java.io.*;
import java.net.*;
import javax.net.ssl.*;

public class testClass {
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String urlStr = "https://car.jp.msn.com/rss/business.aspx";
        try{
            URL url = new URL(urlStr);
            HttpURLConnection http = null;
           
            if (url.getProtocol().toLowerCase().equals("https")) {
                trustAllHosts();
                HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
                https.setHostnameVerifier(DO_NOT_VERIFY);
                http = https;
            } else {
                http = (HttpURLConnection) url.openConnection();
            }
           
            BufferedInputStream bis = new BufferedInputStream(http.getInputStream());
            byte[] buffer = new byte[2048];
            int length = 0;
            byte[] contentBytes = null;
            ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
            while ((length = bis.read(buffer)) >= 0) {
                    baos.write(buffer, 0, length);
            }
           
            contentBytes = baos.toByteArray();
            String result = new String(contentBytes, "utf-8");       
           
            System.out.println(result);
           
            bis.close();
            baos.close();
       
        }catch(Exception e) {
            e.printStackTrace();
        }
       
    }

    private static void trustAllHosts() {
        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new java.security.cert.X509Certificate[] {};
                }

                @Override
                public void checkClientTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType)
                        throws java.security.cert.CertificateException {
                    // TODO Auto-generated method stub
                  
                }

                @Override
                public void checkServerTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType)
                        throws java.security.cert.CertificateException {
                    // TODO Auto-generated method stub
                  
                }
        } };

        // Install the all-trusting trust manager
        try {
                SSLContext sc = SSLContext.getInstance("TLS");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                HttpsURLConnection
                                .setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
  
    final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
        @Override
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    };
}

jsp 소스 ssl증명서 없는 rss 가지고오기

<%@ page contentType = "text/html; charset=utf-8"%>
<%@ page import="java.io.*"  %>
<%@ page import="java.net.*"  %>
<%@ page import="javax.net.ssl.*" %>
<%
    // TODO Auto-generated method stub
    String urlStr = "https://car.jp.msn.com/rss/business.aspx";
    try{
        URL url = new URL(urlStr);
        HttpURLConnection http = null;
       
        if (url.getProtocol().toLowerCase().equals("https")) {
            trustAllHosts();
            HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
            https.setHostnameVerifier(DO_NOT_VERIFY);
            http = https;
        } else {
            http = (HttpURLConnection) url.openConnection();
        }
       
        BufferedInputStream bis = new BufferedInputStream(http.getInputStream());
        byte[] buffer = new byte[2048];
        int length = 0;
        byte[] contentBytes = null;
        ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
        while ((length = bis.read(buffer)) >= 0) {
                baos.write(buffer, 0, length);
        }
       
        contentBytes = baos.toByteArray();
        String result = new String(contentBytes, "utf-8");       
       
        System.out.println(result);
        request.setAttribute("msg", result);
        bis.close();
        baos.close();
   
    }catch(Exception e) {
        e.printStackTrace();
    }
%>
<%!
private static void trustAllHosts() {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return new java.security.cert.X509Certificate[] {};
            }

            public void checkClientTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType)
                    throws java.security.cert.CertificateException {
                // TODO Auto-generated method stub
              
            }

            public void checkServerTrusted(
                    java.security.cert.X509Certificate[] chain,
                    String authType)
                    throws java.security.cert.CertificateException {
                // TODO Auto-generated method stub
              
            }
    } };

    // Install the all-trusting trust manager
    try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection
                            .setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
            e.printStackTrace();
    }
}

final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
    public boolean verify(String hostname, SSLSession session) {
        return true;
    }
};
%>
${msg}

2011년 8월 13일 토요일

MYSQL 정리 02- (update)

http://www.yukun.info/blog/2008/11/mysql-update-delete-record.html


前回はレコードの検索クエリの作成方法を扱いましたが、今回は既存のレコードのフィールド値を更新するUPDATE文と、レコードを削除するDELETE文の練習をしてみます。
まず、扱うテーブル内のレコードの一覧を下記に示します。これは前回と同じです。
1
2
3
4
5
6
7
8
9
10
11
12
mysql> SELECT * FROM book_list;
+---------+--------+--------+-------+-----------------------+
| book_id | title  | author | price | comments              |
+---------+--------+--------+-------+-----------------------+
|       1 | book_A | auth_A |  1500 | good, bad, excellence |
|       2 | book_B | auth_B |  2900 | not bad, good         |
|       3 | book_C | auth_C |  1800 | interesting, amazing  |
|       4 | book_D | auth_D |   700 | sad, depress          |
|       5 | book_E | auth_E |  1200 | good, funny           |
|       6 | book_F | auth_C |  3500 | bored, difficult      |
|       7 | book_G | auth_A |   400 | very good!, excellent |
+---------+--------+--------+-------+-----------------------+

UPDATE文でレコードの更新

それでは試しに、「値段が1000円を超え2000円未満の本を100円値下げする」SQL文を書いてみます。最初は念のため修正するレコードをSELECT文で出力してみます。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT * FROM book_list
    -> WHERE price > 1000
    -> AND price < 2000;
+---------+--------+--------+-------+-----------------------+
| book_id | title  | author | price | comments              |
+---------+--------+--------+-------+-----------------------+
|       1 | book_A | auth_A |  1500 | good, bad, excellence |
|       3 | book_C | auth_C |  1800 | interesting, amazing  |
|       5 | book_E | auth_E |  1200 | good, funny           |
+---------+--------+--------+-------+-----------------------+
次に、UPDATE文で上の本を100円値下げしましょう。
1
2
3
4
5
6
mysql> UPDATE book_list
    -> SET price = price - 100
    -> WHERE price > 1000
    -> AND price < 2000;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
上手くいったようですね。UPDATE文の一般構文は以下のようになります。
UPDATE <テーブル名>
SET <更新する列名1> = <代入する値1> [, <更新列名2> = <代入値2>, ...]
WHERE <条件式>;
WHERE句は省略可能です。SET句内のイコール「=」は代入演算子です(WHERE句の「=」は等価演算子)。複数のフィールドを書き換える際はSET句内の個々の代入式をカンマ「,」で区切ります。UPDATE文は条件に合致する全てのレコードをSET句で書き換えます。実際に書き変わったか確認してみましょう。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT title, price FROM book_list
    -> WHERE price + 100 > 1000
    -> AND price + 100 < 2000;
+--------+-------+
| title  | price |
+--------+-------+
| book_A |  1400 |
| book_C |  1700 |
| book_E |  1100 |
+--------+-------+
確かに、100円値下げしてありますね。

DELETE文でレコードを削除

一般構文は、
DELETE FROM <テーブル名>
WHERE <条件式>;
です。条件に合致する全てのレコードを削除します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql> DELETE FROM book_list
    -> WHERE title = 'book_G';
Query OK, 1 row affected (0.00 sec)
 
mysql> SELECT title FROM book_list;
+--------+
| title  |
+--------+
| book_A |
| book_B |
| book_C |
| book_D |
| book_E |
| book_F |
+--------+
確かに、book_Gが削除されていますね。

リファレンス




http://www.abe-tatsuya.com/web_prog/mysql/update_inner_join.php

MySQL の update 文で inner join する

2009年4月25日 17:47 Add Starkuippa
基本的な SQL 文は MySQL だろうが PostgreSQL だろうが、MS Access だろうが何だろうが、変わりはないんですが、一応メモ。
MySQL の update 文の中で inner join するには、以下のようにします。
update table1
inner join table2 on table1.id = table2.id
set table1.cellname1 = hoge
where table2.cellname2 = 'huga';

MYSQL 정리 01- (SELECT)

http://www.yukun.info/blog/2008/11/mysql-query-select-where-in-like-between.html

  • SELECT文の基本形 – WHERE句
  • 比較文字列内にワイルドカードを指定 – LIKEキーワード、「%」、「_」記号
  • 比較範囲の指定 – BETWEENキーワード
  • 複数のOR結合をIN句でまとめる
  • NOTキーワードで条件の反転
  • NULLフィールドの検索 – IS NULL、IS NOT NULL

SELECT文の基本形 – WHERE句

SELECT文では指定したテーブル(FROM句)に対して、検索条件(WHERE句)にマッチするレコード(行)の指定フィールド(列)を表示します。SELECTに続くのは列名、と覚えましょう。以下、具体例。
SELECT <列名1>[, <列名2>, ...] FROM <テーブル名>
WHERE
<検索条件>;
WHERE句は省略可能。
1
2
3
4
5
6
7
8
9
mysql> SELECT title, price FROM book_list
    -> WHERE
    -> author = 'auth_A';
+--------+-------+
| title  | price |
+--------+-------+
| book_A |  1500 |
| book_G |   400 |
+--------+-------+
author列がauth_Aに合致するレコードを検索し、そのtitle、price列を表示しています。「=」は等価演算子です(代入演算子ではありません)。ちなみに非等価演算子は「<>」です。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT * FROM book_list
    -> WHERE
    -> price < 1500;
+---------+--------+--------+-------+-----------------------+
| book_id | title  | author | price | comments              |
+---------+--------+--------+-------+-----------------------+
|       4 | book_D | auth_D |   700 | sad, depress          |
|       5 | book_E | auth_E |  1200 | good, funny           |
|       7 | book_G | auth_A |   400 | very good!, excellent |
+---------+--------+--------+-------+-----------------------+
アスタリスク「*」はワイルドカードで全ての列を返します。
1
2
3
4
5
6
7
8
9
10
11
mysql> SELECT title, price FROM book_list
    -> WHERE
    -> price >= 1800
    -> AND
    -> author = 'auth_C';
+--------+-------+
| title  | price |
+--------+-------+
| book_C |  1800 |
| book_F |  3500 |
+--------+-------+
WHERE句内の複数の条件を結合する際はAND、ORキーワードを用います。

比較文字列内にワイルドカードを指定 - LIKEキーワード、「%」、「_」記号

WHERE句内の比較条件に用いる演算子の一種と捉えてもいいかもしれません。
1
2
3
4
5
6
7
8
9
mysql> SELECT title, author, comments FROM book_list
    -> WHERE
    -> comments LIKE '%excellen%';
+--------+--------+-----------------------+
| title  | author | comments              |
+--------+--------+-----------------------+
| book_A | auth_A | good, bad, excellence |
| book_G | auth_A | very good!, excellent |
+--------+--------+-----------------------+
「%」は任意の文字列にマッチします。対して「_」任意の1文字にマッチします。

比較範囲の指定 - BETWEENキーワード

price >= 1000 AND price <= 2000の様な条件を簡潔に書くことが出来ます。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT title, price FROM book_list
    -> WHERE
    -> price >= 1000 AND price <= 2000;
+--------+-------+
| title  | price |
+--------+-------+
| book_A |  1500 |
| book_C |  1800 |
| book_E |  1200 |
+--------+-------+
これを書き直すと、
1
2
3
4
5
6
7
8
9
10
mysql> SELECT title, price FROM book_list
    -> WHERE
    -> price BETWEEN 1000 AND 2000;
+--------+-------+
| title  | price |
+--------+-------+
| book_A |  1500 |
| book_C |  1800 |
| book_E |  1200 |
+--------+-------+
確かに実行結果は合致していますね。

複数のOR結合をIN句でまとめる

1
2
3
4
5
6
7
8
9
10
11
mysql> SELECT title, author, price FROM book_list
    -> WHERE
    -> author IN ('auth_A', 'auth_C');
+--------+--------+-------+
| title  | author | price |
+--------+--------+-------+
| book_A | auth_A |  1500 |
| book_C | auth_C |  1800 |
| book_F | auth_C |  3500 |
| book_G | auth_A |   400 |
+--------+--------+-------+

NOTキーワードで条件の反転

LIKE、BETWEEN、IN句と共にも使用することが出来ます。その場合は通常比較フィールドの直前に書きます。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT title, author, price FROM book_list
    -> WHERE
    -> NOT author IN ('auth_A', 'auth_C');
+--------+--------+-------+
| title  | author | price |
+--------+--------+-------+
| book_B | auth_B |  2900 |
| book_D | auth_D |   700 |
| book_E | auth_E |  1200 |
+--------+--------+-------+
だだし、INキーワードではINの直前に書いてもOKです。
1
2
3
4
5
6
7
8
9
10
mysql> SELECT title, author, price FROM book_list
    -> WHERE
    -> author NOT IN ('auth_A', 'auth_C');
+--------+--------+-------+
| title  | author | price |
+--------+--------+-------+
| book_B | auth_B |  2900 |
| book_D | auth_D |   700 |
| book_E | auth_E |  1200 |
+--------+--------+-------+

NULLフィールドの検索 – IS NULL、IS NOT NULL

1
2
3
mysql> SELECT * FROM book_list
    -> WHERE title IS NULL;
Empty set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
mysql> SELECT * FROM book_list
    -> WHERE title IS NOT NULL;
+---------+--------+--------+-------+-----------------------+
| book_id | title  | author | price | comments              |
+---------+--------+--------+-------+-----------------------+
|       1 | book_A | auth_A |  1500 | good, bad, excellence |
|       2 | book_B | auth_B |  2900 | not bad, good         |
|       3 | book_C | auth_C |  1800 | interesting, amazing  |
|       4 | book_D | auth_D |   700 | sad, depress          |
|       5 | book_E | auth_E |  1200 | good, funny           |
|       6 | book_F | auth_C |  3500 | bored, difficult      |
|       7 | book_G | auth_A |   400 | very good!, excellent |
+---------+--------+--------+-------+-----------------------+

リファレンス