データ在庫byte[]の問題
小さなプログラムを書いて、小さな問題を発見します.
bytes[]をデータに追加して取り出します
なぜデータベースから取り出したbyte[]がダメなのか分かりません.
jdk 1.6、データベースmysql 5.0、src contendデータ型、varcharとtextで試したことがありますが、だめです.
もし私がStringをbyte[]に変換してデータベースに保存し、取り出してStringに復元したら、どのように実現しますか?
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();
bytes[]をデータに追加して取り出します
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)); //
なぜデータベースから取り出したbyte[]がダメなのか分かりません.
jdk 1.6、データベースmysql 5.0、src contendデータ型、varcharとtextで試したことがありますが、だめです.
もし私がStringをbyte[]に変換してデータベースに保存し、取り出してStringに復元したら、どのように実現しますか?