变得无效印地文字符串
问题描述:
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.setCharacterEncoding("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
साहिल
साहिलसाहिल
答
显然你的输出是一个单页编码(如ISO-8859-1),而不是UTF-8,这可能有几个原因:
- 你检查过的数据是否正确存储在你的数据库中?如果不是,则应检查用于存储数据的表是否为UTF-8
-
数据库连接是否正确设置为使用UTF-8?我不知道这是ODBC完成,但为MySQL-JDBC驱动程序可能需要附加给你的配置URL:
的characterEncoding = UTF-8
+0
是的,我检查了我的数据被正确存储。 –
+0
你可以在评论中提示我。 –
+0
我已经做到了这一点...但再次不工作 –
我不知道为什么我不能看到图像 –
我已经使用列数据类型varchar(50)和排序规则是utf8_general_ci –
可能的重复[Getting ??????而不是使用JSP的MySQL数据库的印地文文本](http://*.com/questions/7318757/getting-instead-of-hindi-text-from-mysql-database-using-jsp) – BalusC