首页 > 编程知识 正文

java查询access乱码(access数据库 乱码)

时间:2023-12-14 13:33:50 阅读:315564 作者:LTLS

本文目录一览:

java程序从access 数据库读取出来的是乱码,请教高手解决

byte[] bts=null;

String other = null;

bts = rs.getBytes(i); //读取other字段

if(bts != null)

{

other = new String(bts,"gbk");

}

Access数据库必须先一beyet取出来然后进行转码

这个问题我今天解决了

但是我还有个问题,当表名为中文时,查询会出问题,还有列名为中文时取出来的列名也是乱码。帅哥你知道怎么解决这问题不

java写中文到access数据库乱码,java项目的属性为UTF-8

这里要注意3个方面的设置

第一步: 在你自己的servlet里设置

//第一步设置好字体

//设置必须与网页头文件保持一直utf-8 不然依然不管用

response.setContentType("text/html;charset=utf-8");

request.setCharacterEncoding("utf-8");

第二步: 在你的接收页面的设置

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title无标题文档/title

第三步:在你的过滤器里加上相关配置文件

EncodingFilter.java

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.UnavailableException;

public class EncodingFilter implements Filter {

protected String encoding = null;

protected FilterConfig filterConfig = null;

public void destroy() {

this.encoding = null;

this.filterConfig = null;

}

public void doFilter(ServletRequest request, ServletResponse response,

FilterChain chain)

throws IOException, ServletException {

try

{

// System.out.println("过滤开始");

// request.setCharacterEncoding("utf-8");

// chain.doFilter(request, response);

// System.out.println("过滤结束");

} catch (Exception e)

{

e.printStackTrace();

//throw new IOException(e.getMessage());

}

// Select and set (if needed) the character encoding to be used

String encoding = selectEncoding(request);

if (encoding != null) {

request.setCharacterEncoding(encoding);

}

// Pass control on to the next filter

chain.doFilter(request, response);

}

public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;

this.encoding = filterConfig.getInitParameter("encoding");

}

protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}

}

最后要在web.xml里做相关的配置

filter

filter-nameencodingFilter/filter-name

filter-classutil.EncodingFilter/filter-class

init-param

param-nameencoding/param-name

param-valueGBK/param-value/init-param

/filter

filter-mapping

filter-nameencodingFilter/filter-name

url-pattern/*/url-pattern

/filter-mapping

恩 这些都做完的话 就应该没问题了

我的环境是JDK1.5~1.6 MyEclipse6.0

这些只是适用于J2EE工程

java查询access乱码

你的数据库定义name的类型正确么?varchar(45)?试一下用getObject(2);然后再转型打印出来。

大侠你好,我最近用java调用access,系统是win server2003英文版。但是access中汉字读出来是乱码?求解!

你首先要确定你自己的数据库中是什么编码的(包括数据库,表,和字段),再来看你运行的工程是什么编码的,如果你要在页面显示的话也要看一下jsp页面是什么编码格式的,你如果保证了三者的编码格式一致的话,基本不会产生乱码!!!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。