ArrayList<ProductInfo> DataOutput(int a)
 {
  int i=0;
  ArrayList<ProductInfo> PinfoList = new ArrayList<ProductInfo>();
  ProductInfo pinfo = new ProductInfo();
  try {
   result= stmt.executeQuery("select *from product where PSELL='1' and PNO>"+a+";");
   while(result.next())
   { 
    String str1 =null; 
    str1=result.getString("PTITLE");
    System.out.println("title : "+str1);
    String str2 = toUnicode(str1);
    System.out.printf("%s\n",toUnicode(str1));
    System.out.println("title : "+str2);
    String str3 = toLatin1(str1);
    System.out.println("title : "+str3);
    /*
    pinfo.P_No=toUnicode(result.getString("PNO"));
    pinfo.P_Category= toUnicode(result.getString("PCATEGORY"));
    pinfo.P_Title= toUnicode(result.getString("PTITLE"));
    pinfo.P_ImgLocation= toUnicode(result.getString("PIMGLOCATION"));
    pinfo.P_BodyContent=toUnicode(result.getString("PBODYCONTENT"));
    pinfo.P_Sell= toUnicode(result.getString("PSELL"));
    pinfo.P_Buyer= toUnicode(result.getString("PBUYER")); 
    pinfo.P_Guide= toUnicode(result.getString("PGUIDE"));
    pinfo.P_Id= toUnicode(result.getString("ID"));  
    PinfoList.add(pinfo);
    */
    System.out.println("DB 물품 빼내옴"+pinfo.getNo());
    if(i == 10)
    {
     break;
    }
    i++;
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }
  return PinfoList;
 }
 private static String toLatin1(String str)
 {
    try 
    {
     byte[] b = str.getBytes();
     return new String(b,"ISO-8859-1");
    }
    catch(java.io.UnsupportedEncodingException uee) 
    {
     System.out.println(uee.getMessage());
     return null;
    }
 }
    private static String toUnicode(String str)
 {
     if(str == null)
     {
      return null;
     }
    try 
    {
   //  System.out.println("toUnicode");
     byte[] b = str.getBytes("ISO-8859-1");
     return new String(b);
    }
    catch(java.io.UnsupportedEncodingException uee) 
    {
     System.out.println("toUnicode error");
     System.out.println(uee.getMessage());
     return null;
    }
 }
}
 데이터베이스 상태와 서버 실행하고 DB에서 정보를 얻어와서 정보를 찍어 제대로 나왔나 확인한 스샷입니다. 한글이 왜 깨지는지 이유를 잘 모르겠군요.. 제발 좀 알려주세요 ㅜㅜ

이클립스는 utf-8로 설정 되어있습니다.

profile