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