Java读取文件

      这两天一直在做数据库迁移的工作,算是完成了,但是发现,当我从MySQL里导出的sql文件里的数据都是这样的:
INSERT INTO `t_admin_oper_type` VALUES (141, '认证服务管理', 100, 2, 2, 2);
INSERT INTO `t_admin_oper_type` VALUES (142, '页面配置', 100, 2, 3, 3);
INSERT INTO `t_admin_oper_type` VALUES (143, '删除认证服务', 100, 2, 2, 5);
INSERT INTO `t_admin_oper_type` VALUES (144, 'Protal配置', 100, 2, 3, 6);
在表名的地方多出了一对单引号,想来没事做,闲着,就写了一下,Java读取sql文件,再把sql语句重新读取成有效可以直接在Oracle的plsql中插入的数据。
代码如下:
public class SQLUtil {
public static void main(String[] args) throws IOException {
  String fileName= "t_admin.sql";
  InputStream file = new FileInputStream(fileName);
  BufferedReader reader = new BufferedReader(new InputStreamReader(file,"UTF-8"));
  String line = null;
  while((line = reader.readLine())!= null){
    StringBuffer buffer = new StringBuffer();
    int start = line.indexOf("INTO ");
    int end = line.indexOf(" VALUES");
    String tableName = line.substring(start+5, end);
    tableName = tableName.substring(1,tableName.length()-1);
    buffer.append(line.substring(0, start+5));
    buffer.append(tableName.toUpperCase());
    buffer.append(line.substring(end, line.length()));
    System.out.println(buffer.toString()+";");
  }
  reader.close();
 
}
}
运行后的语句结果为:
INSERT INTO t_admin_oper_type VALUES (141, '认证服务管理', 100, 2, 2, 2);
INSERT INTO t_admin_oper_type VALUES (142, '页面配置', 100, 2, 3, 3);
INSERT INTO t_admin_oper_type VALUES (143, '删除认证服务', 100, 2, 2, 5);
INSERT INTO t_admin_oper_type VALUES (144, 'Protal配置', 100, 2, 3, 6);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值