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)
}
}
读取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)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)