我在mysql中将数据存储为¥à¤¨à¥à¤à¤°à¤¨¥。它在localhost中工作正常,但在远程mysql(在plesk中)它无法正常工作。 我使用了以下内容:
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
在servlet和
中con=DriverManager.getConnection("jdbc:mysql://localhost:3306/projectkkm?useUnicode=yes&characterEncoding=UTF-8","root","");
数据库连接中的
<%@page pageEncoding="UTF-8" %>
在jsp中
根据我的研究,我发现问题出在Java中。 java for linux不支持hindi文本,请参阅url:http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html
在我的localhost(Windows)中它的工作正常但是当我将它部署到centos(linux)平台时它无法正常工作。 我认为问题可能出在window / linux兼容性上。
任何人都可以帮我解决这个问题。我确信问题不是来自mysql方面。
答案 0 :(得分:1)
尝试添加,
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
web.xml中的
答案 1 :(得分:0)
好像您的远程数据库配置不正确。
SHOW VARIABLES LIKE 'char%';
应该显示
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
如果没有,你应该修复你/etc/mysql/my.cnf
在[mysqld]部分
中添加以下配置character-set-server = utf8
init-connect='SET NAMES utf8'
collation-server=utf8_general_ci
放入[client]和[mysqldump]部分:
default-character-set=utf8
之后重启mysql
答案 2 :(得分:0)
;WITH ProfileReports AS
(
SELECT pr.ReportId as ReportId
FROM ProfileReport AS pr
INNER JOIN [Profile] AS p ON pr.ProfileId = p.Id AND p.[Status] = 1
INNER JOIN UserProfile AS up ON p.Id = up.ProfileId AND up.[Status] = 1
INNER JOIN [User] AS u ON up.UserId = u.Id AND u.Id = 1 and u.[Status] = 1
),
Parents
AS (SELECT r.Id,
r.ParentId,
r.Name
FROM Report AS r
WHERE r.Id in (select ReportId from ProfileReports ) AND r.[Status] = 1
UNION ALL
SELECT p.Id,
p.ParentId,
p.Name
FROM Report AS p INNER JOIN Parents AS rl ON p.Id = rl.ParentId
WHERE p.[Status] = 1)
,Childs
AS
(
SELECT r.Id,
r.ParentId,
r.Name
FROM Report AS r
WHERE r.Id in (select ReportId from ProfileReports) AND r.[Status] = 1
UNION ALL
SELECT p.Id,
p.ParentId,
p.Name
FROM Report AS p INNER JOIN Childs AS rl ON p.ParentId = rl.Id
WHERE p.[Status] = 1
)
SELECT DISTINCT * FROM (
SELECT * FROM Parents
UNION ALL
SELECT * FROM Childs) t
在tomcat apache服务器配置文件中使用上面的代码