jdbc查询oracle中文乱码,jdbc+oracle 11中文乱码(英文一般)-在线盼

jdbc+oracle 11中文乱码(英文正常)--在线盼。

1.我用select * from web_content在sql plus打印出来的很正常,但运行下面,就出来乱码了,是何故?

2.jdbc:oracle:thin:@127.0.0.1:1521:ORCL?useUnicode=true&characterEncoding=utf-8

此法也不行。

所有代码如下:

package com.hsp.controller;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class index {

Connection ct=null;

Statement sm=null;

ResultSet rs=null;

public ResultSet excuteQuery(String sql){

try {

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";

String user = "scott";

String psw = "tiger";

//得到连接

Connection ct = DriverManager.getConnection(url,user,psw);

//创建Statement

Statement sm;

sm = ct.createStatement();

rs = sm.executeQuery(sql);

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

//删除与插入不能使用executeQuery

return rs;

}//excuteQuery

public static void main(String[] args){

index index=new index();

ResultSet rr=index.excuteQuery("select * from web_content");

try {

if(rr.next()){System.out.print(rr.getString(4));}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}//main

}//index

------解决方案--------------------

字符集的问题,改成这个试试,

System.out.print(rr.getString(4)).getBytes("utf-8");}

------解决方案--------------------

加一个字符过滤器咯!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值