码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • JDBC执行Oracle的Sql脚本注意细节


    1. -- Oracle脚本格式 '/' 与sqlserver中的 go 意义一样
    2. declare
    3. tablecount int;
    4. begin
    5. select count(1) into tablecount from user_tables where table_name = upper('DWD_AA_TABLE');
    6. if tablecount = 1 then
    7. execute immediate 'drop table DWD_AA_TABLE';
    8. end if;
    9. end;
    10. /
    11. create table DWD_AA_TABLE (
    12. fk_voucher varchar2(64) null,
    13. fk_date date null,
    14. datasource varchar2(200) null
    15. --iid int null,
    16. );
    17. /
    18. create index DWD_AA_TABLE_datasource on DWD_AA_TABLE (datasource asc);
    19. /
    20. create index DWD_AA_TABLE_fk_org on DWD_AA_TABLE (fk_org asc);
    21. /
    22. create index gl_accyearbegin_fk_accounttime on DWD_AA_TABLE (fk_accounttime asc);

    下面是代码

    1. private void oraclJDBC() {
    2. String url = "jdbc:oracle:thin:@10.16.1.23:1521:orcl";
    3. String user = "aaa";
    4. String pas = "";
    5. File file_ = null;
    6. try (Connection conn = DriverManager.getConnection(url, user, passwd);) {
    7. conn.setAutoCommit(false);
    8. Statement statement = null;
    9. statement = conn.createStatement();
    10. String sql_txt = "";//从sql脚本中读取到了oracle脚本
    11. List sqls = getSqls(sql_txt);//重点这里***
    12. for (String s : sqls) {
    13. statement.executeUpdate(s);
    14. }
    15. conn.commit();
    16. } catch (Exception ex) {
    17. //conn.rollback();
    18. ex.printStackTrace();
    19. throw new BDException("执行异常文件:" + file_.getName() + " 异常信息:" + ex.getMessage());
    20. }
    21. }
    22. private List getSqls(String str) {
    23. List sqls = new ArrayList<>();
    24. //oracle脚本中要以 '/' 分隔
    25. String[] sql_s = str.split("/");
    26. for (String sql_ : sql_s) {
    27. String sql = sql_.trim();
    28. if (!sql.endsWith("end;")) {//end结尾的必须有; 而非end结尾的不能有;
    29. sql = sql.substring(0, sql.length() - 1);
    30. }
    31. sqls.add(sql);
    32. }
    33. if (CollectionUtils.isEmpty(sqls)) {
    34. throw new BDException("当前脚本无sql");
    35. }
    36. return sqls;
    37. }

  • 相关阅读:
    Postman —— 配置环境变量
    Nacos 注册中心入门及使用
    中国金控盐碱地水稻 国稻种芯-林裕豪:粮食安全两会热点
    将Shopee带到巴黎,印尼MSME产品抢走参观者注意力
    手把手教你定位线上MySQL锁超时问题,包教包会
    muduo库剖析(1)
    智能AI知识库,增强AI知识的开源项目
    (附源码)springboot手工diy网站 毕业设计 310226
    你想知道的do{...}while(0)的作用,都在这里了
    开机优化加速
  • 原文地址:https://blog.csdn.net/qq_41859067/article/details/126571626
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号