1.我用的是sql server数据库。用的是hibernate。
因为要存入大量的字符串数据 大约几十万个字符(中文),
所以我在数据库中把这个字段设置成了image字符集。这样存入把中文转换成二进制存入了数据库。
方法:
数据形式如图:
[img]http://img9.tianya.cn/photo/2009/4/13/12538934_3362767.jpg[/img]
[color=red]2.问题:现在我如何从数据库中取出数据还原成中文的字符串?[/color]
因为要存入大量的字符串数据 大约几十万个字符(中文),
所以我在数据库中把这个字段设置成了image字符集。这样存入把中文转换成二进制存入了数据库。
方法:
/**
*
* @param str
* @return <字符串转换流的形式>
*/
public InputStream convertToInputStream(String str)
{
ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes());
return is;
}
//保存数据库中
byte[] b = new byte[is.available()];
infoRelease.setNewsContent(b);
数据形式如图:
[img]http://img9.tianya.cn/photo/2009/4/13/12538934_3362767.jpg[/img]
[color=red]2.问题:现在我如何从数据库中取出数据还原成中文的字符串?[/color]
//从数据库中取出该表单条记录
InfoRelease infoRelease = (InfoRelease) infoObjectMap.get("return_Data");
//取出字段NewsContent 所对应的字节流
byte[] bt = infoRelease.getNewsContent();
{
//这里如何转化~~~
}