当前位置: 代码迷 >> Java相关 >> orcale 乱码
  详细解决方案

orcale 乱码

热度:630   发布时间:2007-06-18 15:26:14.0
orcale 乱码
我往orcale数据里存了一个"hhfs",从文件里读出来的,但是取出来后却是乱码:
这个是存入的方法
private void insertBlob(Connection conn){
try{


conn.setAutoCommit(false);

Statement st = conn.createStatement();


st.executeUpdate("insert into test1 values('hxc',empty_blob())");



ResultSet rs = st.executeQuery(

"select * from test1 where name='hxc' for update");

if (rs.next()) {




oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("xml");



OutputStream outStream = blob.getBinaryOutputStream();



File file = new File("c:\\ttt.txt");

InputStream fin = new FileInputStream(file);


byte[] b = new byte[blob.getBufferSize()];

int len = 0;

while ( (len = fin.read(b)) != -1) {

outStream.write(b, 0, len);

//blob.putBytes(1,b);

}
fin.close();
outStream.flush();
outStream.close();
conn.commit();
}}catch(Exception e){
e.printStackTrace();
}
}
取出方法:
while(rs.next()){
BLOB blob = (BLOB)rs.getBlob("xml");
byte[] bb = blob.getBytes();

FileOutputStream out = new FileOutputStream("c:\\t1.txt");
out.write(bb);
out.flush();
搜索更多相关的解决方案: orcale  乱码  

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

在数据库中存的是什么格式 取出来就要用这个格式去取


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