package com.test.thread; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.test.entity.Biao; import com.test.jdbc.BaseDao; public class TestThread implements Runnable { List<Biao> lists = new ArrayList<Biao>(0); private String name; BaseDao jdbc = new BaseDao("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@127.0.0.1:1521:orcl","jll","jll"); BaseDao jdbc2 = new BaseDao("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@127.0.0.1:1521:orcl","ll","ll"); public TestThread(String name){ //this.start();jdbc:oracle:thin:@127.0.0.1:1521:orcl //this.setName(name); this.name=name; System.out.println(this.name+" is running....."); String sql = "select id,name,state,count from aa order by id"; lists = jdbc.queryAll(Biao.class, sql, new Object[]{}); System.out.println("select is success...."); } public synchronized void run() { addSql(); /*try { sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } public void addSql(){ String sql="insert into bb values(?,?,?,?)"; if(lists!=null&&lists.size()>0){ for(Biao b:lists){ int count; try { count = jdbc2.insertSql(sql, new Object[]{b.getId(),b.getName(),b.getState(),b.getCount()}); if(count>0){ System.out.println("insert success"); } } catch (SQLException e) { sql= "select id,name,state,count from bb where id=?"; ResultSet rs = jdbc2.getResult(sql, new Object[]{b.getId()}); if(rs!=null){ sql="update bb set state=?,count=count+1 where id=?"; int count2; try { count2 = jdbc2.insertSql(sql, new Object[]{8,b.getId()}); if(count2>0){ System.out.println("mod success"); } } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } } } }


爱情戴罪的羔羊 LV7
2024年4月2日
1529860026 LV24
2023年6月1日
heqian LV17
2023年1月10日
微信网友_6040315240812544 LV8
2022年10月20日
mylzdy LV12
2022年5月12日
3199625134 LV10
2022年4月20日
liju1014
2022年4月5日
暂无贡献等级
xiaoding1999 LV7
2022年4月1日
hai77dong LV3
2021年11月8日
随便取个名字_哈哈 LV27
2021年11月7日