日期:2014-05-16 浏览次数:20493 次
String str="abcdefjackd1234567"; byte bytes[]=str.getBytes(); String sql="insert into test(srccontend) values(?)"; PreparedStatement pst=conn.prepareStatement(sql); pst.setBytes(1,bytes); pst.executeUpdate();
sql="select srccontend from guest where id=60"; pst=conn.prepareStatement(sql); ResultSet rs=pst.executeQuery(); byte []b=null; if(rs.next()){ b=rs.getBytes("srccontend"); System.out.println("b==="+b); } //通过byte[]还原字符串 System.out.println("new String(b)==="+new String(b)); //从数据库中取出不行 System.out.println("new String(bytes)==="+new String(bytes)); //这个可以