首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

字符串怎么存到数据库blob字段

2012-11-18 
字符串如何存到数据库blob字段字符串如何存到数据库blob字段字符串如何存到数据库blob字段?我将字符串存放

字符串如何存到数据库blob字段
字符串如何存到数据库blob字段   
字符串如何存到数据库blob字段?

我将字符串存放到blob字段出现乱码,请问如何解决?是否需要将字符串转换为二进制再存储,如何转换呢? 


字符串如何存到数据库blob字段?
String.getBytes() 可以吗?
我们原来是做成fileinputstream然后set进去。


字符串如何存到数据库blob字段?

用String.getByte()写进去的也是乱码!


字符串如何存到数据库blob字段?
终于解决了,将文本字符串转换为8859-1编码就可以!


字符串如何存到数据库blob字段?
怎样存取图形呢?


字符串如何存到数据库blob字段?


这个是mysql下存取blob字段的一个很简单的类,跟据自己的需要改改就行了

//存取二进制文件到BLOB字段的函数import oracle.sql.BLOB;import oracle.jdbc.driver.OracleResultSet;public void updateBlob(Connection conn,String strFile,long newId,String table_name) {   try {     conn.setAutoCommit(false);     Statement stmt = conn.createStatement();     //stmt.execute("insert into A(A,B) values ('"+strId+"',empty_blob())");     ResultSet rset = stmt.executeQuery("select t.content from "+table_name +" t where id=" + newId +                                        " FOR UPDATE");     BLOB blob = null;     while (rset.next()) {       blob = ( (OracleResultSet) rset).getBLOB(1);     }     File binaryFile = new File(strFile);     FileInputStream instream = new FileInputStream(binaryFile); //读入二进制文件     OutputStream outstream = blob.getBinaryOutputStream();     byte[] buffer = new byte[32];     int length = -1;     while ( (length = instream.read(buffer)) != -1)     outstream.write(buffer, 0, length);     instream.close();     outstream.close();     conn.commit();     conn.setAutoCommit(true);     stmt.close();     conn.close();   }   catch(Exception e){     e.printStackTrace();   }}



热点排行