2021-03-03 曾经终败给现在 2022-11-04 14:23 145阅读 0赞 package com.cyber.jdbc; import java.sql.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.UUID; /** * Author liumz * Date 2021/3/2 21:20 * DESC */ public class Insert2Oracle { private static String url = "jdbc:oracle:thin:@localhost:1521:orcl"; private static String userName = "scott"; private static String passWord = "tiger"; private static String driverName = "oracle.jdbc.OracleDriver"; static{ try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static int execUpdate(String sql, Object[] params){ int rlines = 0; Connection conn = null; PreparedStatement ps = null; try { conn = DriverManager.getConnection(url, userName, passWord); conn.setAutoCommit(false); ps = conn.prepareStatement(sql); if (params != null && params.length > 0){ for (int i = 0; i < params.length; i++) { ps.setObject(i+1, params[i]); } } rlines = ps.executeUpdate(); conn.commit(); } catch (SQLException throwables) { throwables.printStackTrace(); } return rlines; } public static void sql2test(){ String id = UUID.randomUUID().toString().replace("-", "").toLowerCase(); String sql = "INSERT INTO count_table(interfacename,cdate,tablename,realcount)VALUES(?,?,?,?)"; Object[] params = new Object[4]; params[0] = id; params[1] = "2021-03-03 00:00:00"; params[2] = "liumz"; params[3] = 5; execUpdate(sql,params); } public static void main(String[] args) throws Exception { sql2test(); Thread.sleep(1000); /*Connection conn = null; PreparedStatement ps = null; Statement st = null; try { conn = DriverManager.getConnection(url, userName, passWord); st = conn.createStatement(); } catch (SQLException e1) { e1.printStackTrace(); } while (true){ String sql1 = "insert into test1 values(id,?)"; String sql2 = "insert into test2 values(seq_test.nextval,?)"; List<String> list = new ArrayList<>(); list.add(sql1); list.add(sql2); Iterator<String> iter = list.iterator(); while (iter.hasNext()){ String strSql = iter.next(); System.out.println(strSql); try { int i = st.executeUpdate(strSql); if(i>0) { System.out.println("添加成功"); } else { System.out.println("添加失败"); } } catch (SQLException throwables) { throwables.printStackTrace(); } } }*/ } }
相关 C4天梯赛练习总结 (20210302-20210303) > 题目链接:[团体程序设计天梯赛-练习集][-] L1-005 考试座位号 语言:Python (python3) N = int(input()) 我不是女神ヾ/ 2022年11月05日 03:04/ 0 赞/ 129 阅读
还没有评论,来说两句吧...