2011-09-08 13 views
1

&을 데이터베이스에 UTF-8 문자를 가져 오는 중 문제가 있습니다. 삽입이 제대로 발생하지만 표시하는 동안 UTF-8 문자가 표시되지 않습니다. 아래는 제 코드입니다. 내가 어디가 잘못 됐는지 말해 줄 수 있니?ASP classic을 사용하여 데이터베이스에서 utf-8 문자를 읽고 쓰는 방법은 무엇입니까?

파일 : utf8_test.html

 <html><head> 
     <meta http-equiv="content-type" content="text/html;charset=utf-8" /> 
     <title>UTF8</title> 
    </head> 
    <body><DIV align=center> 
     <form action="utf8_insert.asp" method="post"><table> 
      <tr><td>UTF-8:</td><td><input type="text" name="utf8" id="utf8"/></td></tr> 
      <tr><td align="center" colspan="2"><input type="submit" value="submit"></input></td></tr>   
     </table></form> 
    </DIV></body></html> 

파일 : utf8_insert.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
    <% option explicit 
    dim objConn, objRS , strSql, input, test 
    Response.CodePage = 65001 
    Response.CharSet = "utf-8" %> 
    <html> 
    <head><title>Test UTF </title> 
    <meta http-equiv="content-type" content="text/html;charset=utf-8" /> 
    <head/> 
    <body> 
    <h1>Test UTF </h1> 
    <% 
     'File saved in ANSI - also works in UTF-8 
     input = Request.Form("utf8") 
     test = "多语言测试 test" 
     response.write "Test: " + test + "</br></br>" 
     session("norm_dsn") ="dsn=norm_dsn;driver=SQL Server;uid=username;pwd=password" 
     set objConn=server.CreateObject("ADODB.Connection") 
     objConn.Open session("norm_dsn") 
     strSql = "INSERT INTO test_utf8 (text, date_log) VALUES ('" + input +"', sysdate)" 
     objConn.execute(strSql) 
     set objRS = Server.CreateObject("ADODB.RECORDSET") 
     strSql="select * from test_utf8 order by date_log" 
     set objRS=objConn.execute(strSql) 
     while NOT objRS.EOF 
      response.write objRS("text") & "</br>" 
      objRS.MoveNext 
     wend 
     objRS.close 
     set objRS = nothing 
     objConn.Close 
     set objConn=nothing 
    %> 
    </body></html> 

답변

3

난 당신이 사용하고있는 SQL 서버 몰라,하지만 당신은 MS SQL 서버를 사용하는 경우이 있어야한다 유니 코드 문자열 앞에 접두어. N'myString'.

접두사는 후속 문자열이 유니 코드임을 나타냅니다. 유니 코드 문자열 상수에 N을 접두사로 사용하지 않으면 SQL Server는 문자열을 사용하기 전에이를 현재 데이터베이스의 비 유니 코드 코드 페이지로 변환합니다.

http://support.microsoft.com/kb/239530

예 :

insert into myTable (columnName) values(N'My unicode string goes here') 

이 또한 ASP 파일의 인코딩 문자열을 처리하는 방법에 영향을 줄 수 있습니다. .ASP 파일을 디스크에 utf-8로 저장해보십시오.

기타 :이 스레드를 참조하십시오 : internal string encoding

+0

나는 이것을 위해 Oracle 11g를 사용하고 있습니다. 현재이 '建議 替代 方案'을 입력하면 DB에 제대로 저장되지만 '建 æ> ¿ 代 æ-¹æ¡'와 같은 것을 가져옵니다. UTF-8로 변환하면 삽입 한 내용이 표시되기 때문에 올바른 것입니다. –

+0

그래서 데이터베이스를 보면 '建議 替 代 方案? – David

+0

파일을 UTF-8 및 ANSI로 저장하려고했습니다. 출력은 같습니다. –