´ÙÀ½ ÀÌÀü Â÷·Ê

8. PostgreSQL ÀÇ JDBC ¿¡ ¿¬µ¿ ¹× ÇѱÛó¸®

8.1 PostgreSQL ÀÇ JDBC ¿¬µ¿

Tomcat 3.1 ¿¡ postgreSQLÀÇ JDBC ¿¬µ¿Àº ÀÇ¿Ü·Î °£´ÜÇÏ´Ù. ȯ°æº¯¼ö CLASSPATH ¿¡ µî·ÏÇϱ⸸ ÇÏ¸é µÈ´Ù. ±×·¯¸é Tomcat ½ÇÇà½Ã ÀÚµ¿À¸·Î Àо JDBC ¸¦ ·ÎµùÇÑ´Ù.

CLASSPATH ¼³Á¤ ¿¹

   export  CLASSPATH=$CLASSPATH:/usr/local/pgsql7.0.2/jdbc/postgresql.jar

8.2 Tomcat ¿¡¼­ÀÇ ÇÑ±Û Ã³¸®

Tomcat ¿¡¼­ÀÇ ÇѱÛ󸮴 Apache-Jserv ¿Í µ¿ÀÏÇÏ´Ù.

¾Æ·¡´Â °³·«ÀûÀÎ ¼Ò½ºÀÔ´Ï´Ù.

  ..............
  ..............

  public void doGet(HttpServletRequest req , HttpServletResponse res)
  throws ServletException,IOException 
  {
    .......
    .......
    PrintWriter out;
    res.setContentType("text/html;charset=euc-kr");
    out=new PrintWriter(new OutputStreamWriter(
                     res.getOutputStream(),"KSC5601")); 
    .......
    .......
 }
   .....
   .....
  public  void doPost(HttpServletRequest req, HttpServletResponse res)
  throws ServletException,IOException 
  {
    res.setContentType("text/html;charset=euc-kr");
    PrintWriter out=new PrintWriter(new OutputStreamWriter(
                                    res.getOutputStream(),"KSC5601"));
    ....
    String id=ksc(req.getParameter("id"));
    String name=ksc(req.getParameter("name"));
    String juso=ksc(req.getParameter("juso"));
    String tel=ksc(req.getParameter("tel"));
    String memo=ksc(req.getParameter("memo"));
    ....
    ....
  }
    .....
    .....

  public String ksc(String kscstr)
  throws UnsupportedEncodingException
  {
   if(kscstr==null) return null;
   return new String(kscstr.getBytes("8859_1"),"KSC5601");
  } //  ksc() ÇÔ¼ö´Â ¹®ÀÚ¸¦ KSC5601·Î º¯È¯ÇÑ´Ù.

  ............................................................

8.3 PostgreSQL 7.0.2's JDBC ¿¡¼­ÀÇ ÇѱÛó¸®

¶ÇÇÑ Æ÷½ºÆ®±×·¹½º7.0.2¿¡ ÇѱÛÀ» »ðÀÔÇϱâÀü¿¡ KSC5601·Î º¯È¯ÇÏ¿©¾ß ÇÑ´Ù. ±×·¸Áö ¾ÊÀ¸¸é Æ÷½ºÆ®±×·¹½º¿¡ µé¾î°£ ÇѱÛÀº ¹Ù·Î ±úÁø´Ù. ±âŸ ´Ù¸¥ ¹öÁ¯Àº ¾Æ¸¶ ºñ½ÁÇÒ °Å·Î ÃßÃøµÇ¸ç ¾ÆÁ÷ Å×½ºÆ®´Â ¸øÇØ º¸¾Ò´Ù.

¾Æ·¡Ã³·³ ¹®ÀÚ¸¦ ksc()ÇÔ¼ö·Î ksc5601 ·Î º¯È¯ÇÑ ÈÄ¿¡ Æ÷½ºÆ®±×·¹½º¿¡ insert ÇÏ¸é µÈ´Ù.

  String id=ksc(req.getParameter("id"));
  String name=ksc(req.getParameter("name"));
  String juso=ksc(req.getParameter("juso"));
  String tel=ksc(req.getParameter("tel"));
  String memo=ksc(req.getParameter("memo"));

´ÙÀ½ ÀÌÀü Â÷·Ê