oracle的clob字段的存取问题?

mygerald 2004-12-07 03:22:53
插入操作的代码为:
.....
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,userid);
byte [] bStr = content.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(bStr);
pstmt.setAsciiStream(2, bis ,content.length());
pstmt.executeUpdate();
.....


读取操作的代码为:
.....
try{
CLOB clob = (oracle.sql.CLOB)rs.getClob(fldname);
if(clob!=null){
BufferedReader br=new BufferedReader(clob.getCharacterStream());
String data = null;
if((data = br.readLine())!=null)
strinfo.append(data);
try {
while ( (data = br.readLine()) != null)
strinfo.append('\r').append('\n').append(data);
}
catch(Exception ex){
}
}
}
catch(Exception e){
}
.....
为什么我存入的中文取出来的都是问号呢????e文的就没有问题,请csdn上各位高手相助!!
...全文
165 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mygerald 2004-12-07
  • 打赏
  • 举报
回复
我加了字符集过滤器了
wangxiaomax 2004-12-07
  • 打赏
  • 举报
回复
使用filter
web.xml
<filter>
<filter-name>characterfilter</filter-name>
<filter-class>CharacterFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

CharacterFilter.java

public class CharacterFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(selectEncoding(request));
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
public FilterConfig getFilterConfig() {
return filterConfig;
}
public void setFilterConfig(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
}
mygerald 2004-12-07
  • 打赏
  • 举报
回复
没有人会吗?????????

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧