首页>代码>利用java线程实现数据上传demo>/ThreadTest/src/com/test/thread/TestThread.java
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();
										}
									}
							}	
					}	
			}	
	}
}
最近下载更多
newbag  LV9 2021年8月9日
wsfdwr  LV10 2019年7月10日
liuyishi  LV6 2019年4月6日
aaayyy1437  LV2 2019年3月8日
加加活宝  LV2 2018年8月1日
橙cheng001  LV8 2018年6月29日
ldjsaflj  LV1 2018年6月20日
lipiao161  LV16 2018年3月29日
wgc_jy  LV21 2018年1月5日
fxhh5057  LV13 2017年5月12日
最近浏览更多
爱情戴罪的羔羊  LV7 4月2日
1529860026  LV24 2023年6月1日
heqian  LV16 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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友