本文目錄一覽:
- 1、java程序從access 數據庫讀取出來的是亂碼,請教高手解決
- 2、java寫中文到access數據庫亂碼,java項目的屬性為UTF-8
- 3、java查詢access亂碼
- 4、大俠你好,我最近用java調用access,系統是win server2003英文版。但是access中漢字讀出來是亂碼?求解!
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頁面是什麼編碼格式的,你如果保證了三者的編碼格式一致的話,基本不會產生亂碼!!!
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/227710.html