开发者

getting invalid hindi string from mysql using jsp

here are the settings

this time using odbc connection

![showing u the settings][1]


[1]: http://i.stack.imgur.com/4f2bD.jpg

and

![ i have mentioned utf8 here][1]


[1]: http://i.stack.imgur.com/C9fo5.jpg

here is my code


<%-- 
Document   : index.jsp
Created on : 30 Aug, 2011, 10:57:05 AM
Author     : Sahil
--%>
<%@page contentType="text/html" pageEncoding="UTF-8" import = "java.sql.*;"%>
<%@page import = "java.util.*"%>
<%@ page import = "java.io.*"%> 
<%@page import= "java.lang.RuntimePermission" %>
<!DOCTYPE html>
<html>
<head>
 <title>Punjabi-Hindi Dictionary | Output</title>
 <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
  <form accept-charset="UTF-8">  
    <%

    try
      { 
       if (request.getCharacterEncoding() == null) 
           request.setCharacterEncod开发者_运维知识库ing("UTF-8");
       Connection cn;

       Statement st;
       ResultSet rs;
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       cn=DriverManager.getConnection("jdbc:odbc:myodbc","root","");
       st=cn.createStatement();   
       rs=st.executeQuery("select * from stu_info");
       while(rs.next()){
       String Name= rs.getString("Name");

     %> 
     <%=Name%>
     <br>
      <%
                        }
     rs.close();
     st.close();
     cn.close();
     }
     catch(Exception ex)
     {
      out.println(ex.getMessage());
     }
      %>

    </form>    
    </body>
  </html>

  this time it gives me diffrent output

  साहिल
  साहिलसाहिल 


Obviously your output is in a single page encoding (e.g. ISO-8859-1) and not in UTF-8, this can have several reasons:

  • Have you checked the data is correctly stored in your database? If not, you should check if the table you use for storing the data is UTF-8
  • Is your database connection properly set up to use UTF-8? I don't know how this is done for odbc, but for the mysql-jdbc Driver you might need to append this to your configuration url:

    characterEncoding=utf-8

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜