JDBC 中文问题 有什么方法解决 java 程序到 数据库中文乱码的问题.我是用jbuilder+mysql.用什么方法? 知道的多罗列几种.详细点好.谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其实mysql解决了中文问题就可以了。你可以在配置mysql的时候选择gb2312.网上有处理的具体方法,去看看吧!很管用的。 在设置URL的时候就可以直接搞定了吧URL="jdbc:mysql://localhost/dbname?user=username&password=password&useUnicode=false&characterEncoding=gbk"这样应该就可以了当然也可以对传入DB的字符做编码规定,String ss;String s = new (ss.getBytes("iso-8859-1"),"gbk"); 写个Filter在web.xml中配置下public class EncodingFilter extends HttpServlet implements Filter { private static final long serialVersionUID = 1L; /* 过滤器引用 */ private FilterConfig filterConfig = null; /* 字符集变量 */ private String charSet = null; /* 过滤器转换字符集 */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { /* 获得应用程序配置的字符集 */ charSet = (String) filterConfig.getInitParameter("charSet"); /* 设置Http字符集的请求为系统的默认字符集 */ HttpServletRequest req = (HttpServletRequest) request; req.setCharacterEncoding(charSet); /* 获得Http的响应 */ HttpServletResponse res = (HttpServletResponse) response; /* 转发道请求的资源 */ chain.doFilter(req, res); } catch (Exception e) { System.out.println("EncodingFilter " + e.getMessage()); } } /* 过滤器销毁 */ public void destroy() { this.filterConfig = null; this.charSet = null; } /* 过滤器初始化 */ public void init(FilterConfig filterConfig) { this.filterConfig = filterConfig; }}在web.xml中加入 <filter> <filter-name>EncodingFilter</filter-name> <filter-class>com.test.EncodingFilter</filter-class> <init-param> <param-name>charSet</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 我上次连数据库也是有问题,有个最简单的方法:把所有的字符集都设置为“gb2312”数据库里的也一样选择,注意在从web页提交给javaBEAN之前把字符集转换一次为“gb2312”就可以成功提交了。% request.setCharacterEncoding("gb2312");<---先转换,再提交 %><jsp:useBean id="Customer" scope="page" class="com.ebook.common.Customer"/><jsp:setProperty name="Customer" property="*"/> java输出的问题 有关JAVA二分法的算法 ajax如何传递对象 求助——怎样在JFrame 上面放一个图片(图片放在指定位置) 关于组建的属性 谁知道如何得到java中某一个对象所占用的内存是多大?要求精确的知道 问网络通信方面高手 救命!! 谁能介绍几本java与网络编程有关的好书? 门外汉:java的和平台无关性? 为什么打包成功不能运行 //程序中这种用法第一次看到,请问各位碰到过吗?
当然也可以对传入DB的字符做编码规定,String ss;
String s = new (ss.getBytes("iso-8859-1"),"gbk");
public class EncodingFilter extends HttpServlet implements Filter { private static final long serialVersionUID = 1L; /* 过滤器引用 */
private FilterConfig filterConfig = null; /* 字符集变量 */
private String charSet = null; /* 过滤器转换字符集 */
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
/* 获得应用程序配置的字符集 */
charSet = (String) filterConfig.getInitParameter("charSet"); /* 设置Http字符集的请求为系统的默认字符集 */
HttpServletRequest req = (HttpServletRequest) request;
req.setCharacterEncoding(charSet); /* 获得Http的响应 */
HttpServletResponse res = (HttpServletResponse) response; /* 转发道请求的资源 */
chain.doFilter(req, res);
} catch (Exception e) {
System.out.println("EncodingFilter " + e.getMessage());
}
} /* 过滤器销毁 */
public void destroy() {
this.filterConfig = null;
this.charSet = null;
} /* 过滤器初始化 */
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
}在web.xml中加入
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.test.EncodingFilter</filter-class>
<init-param>
<param-name>charSet</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
把所有的字符集都设置为“gb2312”数据库里的也一样选择,
注意在从web页提交给javaBEAN之前把字符集转换一次为“gb2312”就可以成功提交了。% request.setCharacterEncoding("gb2312");<---先转换,再提交
%>
<jsp:useBean id="Customer" scope="page" class="com.ebook.common.Customer"/>
<jsp:setProperty name="Customer" property="*"/>