码农知识堂 - 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. }

  • 相关阅读:
    nginx负载均衡
    云原生爱好者周刊:使用 eBPF 实现 PostgreSQL 的可观测性
    命令执行绕过 [GXYCTF2019]Ping Ping Ping1
    【C语言程序设计】实验 5
    C#/VB.NET 实现Word和ODT文档相互转换
    Kubernetes Gateway API 攻略:解锁集群流量服务新维度!
    诗诺克科技引领数字资产智能交易革命
    婴儿肠绞痛怎么办?
    【操作系统】I/O 管理(一)—— I/O 管理概述
    nginx 记录每个IP连接的流量大小多少KB
  • 原文地址:https://blog.csdn.net/qq_41859067/article/details/126571626
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号