oracle数据库中将clob字段内容利用java提取出至文本文档中
代码段:
1.执行clob转String
public static String ClobToString(Clob sc) throws SQLException, IOException {
String reString = "";
Reader is = sc.getCharacterStream();
// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
return reString;
}
2.主类执行循环读取数据库+将转换内容存储至文本文档
public static void main(String[] args) {
Connection connect = null;
Statement statement = null;
ResultSet resultSet = null;
ResultSet resultSet1 = null;
PreparedStatement preState = null;
PreparedStatement preState1 = null;
try {
// 利用Driver对象
Driver driver = new OracleDriver();
DriverManager.deregisterDriver(driver);
Properties pro = new Properties();
pro.put("user", "用户名");
pro.put("password", "密码");
connect = driver.connect("jdbc:oracle:thin:@地址:端口:数据库名", pro);
// 查询所有
String sql1 = "数据库相关查询语句";
preState1 = connect.prepareStatement(sql1);
resultSet1 = preState1.executeQuery();
while (resultSet1.next()) {
//打印相关字段名,看看验证一下是否是想要的字段
System.out.println(resultSet1.getString("字段名"));
//定义其中变量(试个人数据库语句情况而定可取舍)
String str = resultSet1.getString("字段名");
//验证一下打印字段是否正确
System.out.println(str);
String sql = "相关查询语句";
preState = connect.prepareStatement(sql);
resultSet = preState.executeQuery();
while (resultSet.next()) {
String content = ClobToString(resultSet.getClob("自定义字段或表名"));
BufferedWriter bw = null;
try {
//相关路径为:src\\clobtest\\newfile.txt这个是我自己本地路径(视个人情况而修改)
bw = new BufferedWriter(new FileWriter("src\\clobtest\\newfile.txt", true));
// for (int j = 0; j < 1; j++) {
bw.write(content + '\n');
// }
bw.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null) {
bw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭资源
try {
if (resultSet != null)
resultSet.close();
if (preState != null)
preState.close();
if (statement != null)
statement.close();
if (connect != null)
connect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
知识点:clob转换至string、jdbc:oracle数据库连接、基本读取集合内容至文本文档。
oracle数据库中将clob字段内容利用java提取出至文本文档中的更多相关文章
- 编写Java程序,读取文本文档的内容,去除文本中包含的“广告”字样,把更改后的内容保存到一个新的文本文档中
查看本章节 查看作业目录 需求说明: 读取文本文档的内容,去除文本中包含的"广告"字样,把更改后的内容保存到一个新的文本文档中 实现思路: 在main() 方法中,使用 new F ...
- Java 写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档
写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档 import java.io.File; import java.io.FileNotFoundException; import ...
- Java 单字节、多字节读取文本文档中的内容
文本文档位于工程下. 鼠标右击工程,选择“new - File”,即可创建. 文本文档的格式:GBK 单字节读取 import java.io.File; import java.io.FileInp ...
- 文本文档中各字母出现次数汇总(java)
package 字母频率统计; import java.io.*; public class Inputfile { public static void main(String args[]) { ...
- Oracle数据库 获取CLOB字段存储的xml格式字符串指定节点的值
参照: Oracle存储过程中使用游标来批量解析CLOB字段里面的xml字符串 背景:在写存储过程时,需要获取表单提交的信息.表单信息是以xml格式的字符串存储在colb类型的字段dataxml中,如 ...
- Java提取文本文档中的所有网址(小案例介绍正则基础知识)
正则表达式基础以及Java中使用正则查找 定义: 正则表达式是一些用来匹配和处理文本的字符串 正则的基础(先大致了解下) 1. 正则表达式的作用 查找特定的信息(搜索) 替换一些文本(替换) 2. 正 ...
- 过滤文本文档中的数据并插入Cassandra数据库
代码如下: package com.locationdataprocess; import java.io.BufferedReader; import java.io.File; import ja ...
- 基于Oracle数据库登陆界面及功能实现 Java版
首先要在Oracle数据库创建表文件,包括建立表头以及关键字(唯一标识符),此次程序所用的表名称为SW_USER_INFO,表头有UNAME.UKEY.USEX等,关键字为UCC,然后添加一条记录,用 ...
- oracle数据库对date字段类型存在空值进行排序的处理方法
oracle数据库对date字段类型存在空值进行排序的处理方法 oracle 数据库,如果表中有一个字段类型为date,且该字段类型存在空值,并且需要排序, 解决方法为使用oracl ...
随机推荐
- Git 搭建私有仓库
简介: 如果你不想把自己的代码公开让别人阅读.使用,也不想花钱购买 GitHub 私有仓库,那么你就需要自己动手做一个了. 当然你也可以使用 Coding.net ,上面可以创建免费的私有仓库.( 今 ...
- easyui datagrid combobox下拉框获取数据问题
最近在使用easyui的datagrid,在可编辑表格中添加一个下拉框,查了下API,可以设置type : 'combobox',来做下拉框,这下拉框是有了,可是这后台数据怎么传过来呢,通过查API可 ...
- 封装basedao
package com.huawei.common; import java.sql.ResultSet;import java.sql.SQLException; public interface ...
- call和callvirt
call以非虚方式调用虚函数. callvirt以虚方式调用虚函数,调用的时候会判断真正引用的对象,调用该类型的
- Vertex and fragment programs
[Vertex and fragment programs] When you use vertex and fragment programs (the so called "progra ...
- RGB颜色核对的网址
http://www.917118.com/tool/color_3.html 首页 人民币大写转换 颜色总览 颜色中文名称对照表 CMYK颜色对照表 RGB颜色对照表 色阶板 颜色代码表 调色板 ...
- 543. Diameter of Binary Tree 二叉树的最大直径
[抄题]: Given a binary tree, you need to compute the length of the diameter of the tree. The diameter ...
- [JAVA] 冻结Excel的第一行或第一列
可以按照如下设置创建冻结窗口. sheet.createFreezePane( 3, 2, 3, 2 ); 前两个参数是你要用来拆分的列数和行数.后两个参数是下面窗口的可见象限,其中第三个参数是右边区 ...
- ssh 连接缓慢解决方法
ssh 连接缓慢解决方法 摘自:https://blog.csdn.net/qq_14821541/article/details/61915589 2017年03月13日 12:00:38 所以怎样 ...
- pagespeed模块安装——Nginx、Tengine
1.安装好nginx或者tengine 2.下载pagespeed模块并且解压 sudo mkdir -p /usr/local/tengine/modules wget https://github ...