안드로이드 개발 질문/답변
(글 수 45,052)
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로 설정 되어있습니다.





MySQL 설치 하실 때 캐릭터 셋을 무엇으로 주셨나요?
설치 후 변경하려고 해도 실제로 변경 안되는 경우가 많습니다.
설치시 캐릭터 셋은 기본으로 '라틴 어쩌구' 입니다.
이것을 utf-8 또는 euc-kr로 하셔야 합니다.
만약 설치시 캐릭터셋을 제대로 지정안하셨다면 다시 설치하시기를 권합니다.