mysql读取text 大文本 20
@Testpublicvoidread(){try{conn=JdbcUtils.getConnection();Stringsql="selectresumefromt...
@Test
public void read() {
try {
conn = JdbcUtils.getConnection();
String sql = "select resume from testclob where id=1";
pt = conn.prepareStatement(sql);
rs = pt.executeQuery();
if (rs.next()) {
Reader reader = rs.getCharacterStream("resume");
char buffer[] = new char[1024];
while ((reader.read(buffer)) != -1) {
System.out.println(buffer);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtils.release(conn, pt, rs);
}
}
我存在数据库的大文本超过 char数组的预定大小 每次只能读取大部分 我想读完全部 应该怎么改程序? 展开
public void read() {
try {
conn = JdbcUtils.getConnection();
String sql = "select resume from testclob where id=1";
pt = conn.prepareStatement(sql);
rs = pt.executeQuery();
if (rs.next()) {
Reader reader = rs.getCharacterStream("resume");
char buffer[] = new char[1024];
while ((reader.read(buffer)) != -1) {
System.out.println(buffer);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtils.release(conn, pt, rs);
}
}
我存在数据库的大文本超过 char数组的预定大小 每次只能读取大部分 我想读完全部 应该怎么改程序? 展开
展开全部
读取mysql数据库文本字段的值方法如下:
public void read() {
try {
//连接数据库
conn = JdbcUtils.getConnection();
//查询resume字段,text格式
String sql = "select resume from testclob where id=1";
pt = conn.prepareStatement(sql);
//执行查询并返回结果
rs = pt.executeQuery();
if (rs.next()) {
// rs.getCharacterStream读取该字段
Reader reader = rs.getCharacterStream("resume");
//定义字符数组来存放读取值
char buffer[] = new char[1024];
while ((reader.read(buffer)) != -1) {
//打印
System.out.println(buffer);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtils.release(conn, pt, rs);
}
}
public void read() {
try {
//连接数据库
conn = JdbcUtils.getConnection();
//查询resume字段,text格式
String sql = "select resume from testclob where id=1";
pt = conn.prepareStatement(sql);
//执行查询并返回结果
rs = pt.executeQuery();
if (rs.next()) {
// rs.getCharacterStream读取该字段
Reader reader = rs.getCharacterStream("resume");
//定义字符数组来存放读取值
char buffer[] = new char[1024];
while ((reader.read(buffer)) != -1) {
//打印
System.out.println(buffer);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
JdbcUtils.release(conn, pt, rs);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |