package dbtest; import java.io.UnsupportedEncodingException; import java.sql.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { public static void main(String[] args) { String url="jdbc:oracle:thin:@10.70.80.22:1521:orcl"; String userName="ybxt1"; String password="ybxt1"; try { Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection(url, userName, password); PreparedStatement preStmt=conn.prepareStatement("select jh from daa01 where jh =?"); //如果在源文件里硬编码参数,则应该按照:源文件charset->数据库charset 的顺序将 //参数转换成数据库可以识别的格式;在取回数据时,应按照:数据库文件charset->源文件(或目标平台)charset //的顺序来转换。 String jh=new String("洼38-东H2".getBytes("GB2312"), "ISO8859-1"); preStmt.setString(1, jh); ResultSet rs=preStmt.executeQuery(); while (rs.next()) { System.out.println("working"); System.out.println(new String(rs.getString(1).getBytes("ISO8859-1"),"GB2312")); } } catch (ClassNotFoundException ex) { System.out.println("OracleDriver not found"); } catch (SQLException sqlex) { System.out.println("sql exception"); } catch (UnsupportedEncodingException usee) { System.out.println("unsupportedException exception"); } } }