从数据库读取到的字段怎么输出

Jyie_DK 2010-09-03 05:56:41
我从SQL2005读取到了一个字段,但是怎么把这个字段的全部值打印出来呢
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
UPC_思念 2010-09-04
  • 打赏
  • 举报
回复
顶起。。。。。。
jiang521725 2010-09-03
  • 打赏
  • 举报
回复
呵呵,关注你
wula0010 2010-09-03
  • 打赏
  • 举报
回复
要注意文本的字符集转换:

while (rs.next()) {
Map map = new HashMap();
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
if (rsmd.getColumnTypeName(i).equals("text")) {
StringBuffer sbf = new StringBuffer();
java.io.InputStream ins = rs.getAsciiStream(i);
int ch = 0;
if (ins != null) {
try {
while ((ch = ins.read()) != -1) {
sbf.append((char) ch);
}
ins.close();
map.put(rsmd.getColumnName(i), new String(sbf.toString().getBytes("8859_1"), "GB2312"));
} catch (IOException ioe) {
throw new AppException(this.getClass().getName() + ":_eexecuteQuery(final String sql, final List params):pstmt.executeQuery()失败。IOException错误信息:" + ioe.getMessage() + "。sql:" + sql);
}
} else {
map.put(rsmd.getColumnName(i), null);
}
}else{
map.put(rsmd.getColumnName(i), rs.getObject(i));
}
}
getListResult().add(map);
}
dr_lou 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dr_lou 的回复:]
while(rs.next(){
System.out.println(rs.getString(0));
}
[/Quote]

好像是getString(1);
wyang1991 2010-09-03
  • 打赏
  • 举报
回复
循环遍历


while(rs.next()){

}
dr_lou 2010-09-03
  • 打赏
  • 举报
回复
while(rs.next(){
System.out.println(rs.getString(0));
}

62,623

社区成员

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

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