本文介绍了Java PreparedStatement UTF-8 字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个准备好的声明:

I have a prepared statement:

PreparedStatement st;

在我的代码中,我尝试使用 st.setString 方法.

and at my code i try to use st.setString method.

st.setString(1, userName);

userName 的值为 şakça.setString 方法将şakça"更改为?akça".它不识别 UTF-8 字符.我该如何解决这个问题?

Value of userName is şakça. setString methods changes 'şakça' to '?akça'. It doesnt recognize UTF-8 characters. How can i solve this problem?

谢谢.

推荐答案

这可能被搞砸的方式数量实际上相当令人印象深刻.如果您使用的是 MySQL,请尝试将 characterEncoding=UTF-8 参数添加到 JDBC 连接 URL 的末尾:

The number of ways this can get screwed up is actually quite impressive. If you're using MySQL, try adding a characterEncoding=UTF-8 parameter to the end of your JDBC connection URL:

jdbc:mysql://server/database?characterEncoding=UTF-8

您还应该检查表/列字符集是否为 UTF-8.

You should also check that the table / column character set is UTF-8.

这篇关于Java PreparedStatement UTF-8 字符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 21:46