JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--JAVA技术--JAVA线程  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
java多线程数据库操作
作者:未知     文章来源:www.jspcn.net
访问次数:2186次     加入时间:2005年01月19日
import java.io.*;
import java.sql.*;

public class ToOracle {
public static void main(String[] args) {
int n = 10;//每个线程执行的个数
//System.out.println("start action!!!!!!");
ToOracle ac = new ToOracle();
ThreadRun[] testrun = new ThreadRun[21];

for (int i = 1; i <= 21; i++) {
testrun[i] = ac.new ThreadRun();
testrun[i].TRun(n);
System.out.println("线程" + i + "已经启动");
}

//testrun[1] = ac.new ThreadRun();
//testrun[1].TRun(10);
for (int i = 1; i <= 21; i++) {
testrun[i].TExit();
}
}

class ThreadRun {
String blobname = "D:eclipse est est1.txt"; //blob文件名

String clobname = "D:eclipse est est2.txt"; //clob文件名

String in = "insert into ";

String in1 = "(order_id,ric_code,siz,price,trade_datetime,status,testblob,testclob) values(9,´asdfjkl´,21,123.34567,sysdate,´nill逆耳´,?,?)";

String tablename = "orders1";

String sqlstr = ""; // sql 语句

ThreadUseExtends thread = new ThreadUseExtends(blobname, clobname,
sqlstr);

public void TRun(int n) {
sqlstr = in + tablename + in1;
thread = new ThreadUseExtends(blobname, clobname, sqlstr);
//thread.start();
thread.run(n);
/*
* int n=10; for (int i = 1; i <= 21; i++) { while(0 <n){ sqlstr[i] =
* in + tablename + in1; thread[i] = new ThreadUseExtends(blobname,
* clobname, sqlstr[i]); thread[i].start(); n--; }
* System.out.println("线程" + i + "已经启动"); }
*/

//System.out.println("线程1已经启动");
}

public void TExit() {
thread.interrupt();
}

class ThreadUseExtends extends Thread {
String filename1;//blob filename

String filename2;//clob filename

String str;

//构造函数要有(blob文件名,clob文件名,sql语句)
public ThreadUseExtends(String name1, String name2, String sqlstr) {
filename1 = name1;
filename2 = name2;
str = sqlstr;
}

ReadFiles r1 = new ReadFiles();

public void run(int n) {
while (n > 0) {
try {
String url = "jdbc:oracle:thin:@193.9.200.111:1521:ora9i";
String login = "system"; // use your login here
String password = "ti2003"; // use your password here
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(url,
login, password);
String testLong = r1.ReadFile(filename1);
String testLong1 = r1.ReadFile(filename2);
byte[] ba = testLong.getBytes();
System.out.println("str=" + str);
//String strSql = str; //"insert into
// orders(order_id,ric_code,siz,price,trade_datetime,status,testblob,testclob)
// values(8,´asdfjkl´,21,123.34567,sysdate,´nill逆耳´,?,?)";
PreparedStatement stm = con.prepareStatement(str);

stm.setBytes(1, ba);
StringReader test = new StringReader(testLong1);
stm.setCharacterStream(2, test, testLong.length());
stm.execute();
stm.close();
con.close();

} catch (Exception e) {
e.printStackTrace();
}
n--;
}//while

}//run

}//ThreadUseExtends class

// ReadFiles class for read text!!
class ReadFiles {
public ReadFiles() {
}

//ReadFile method,read file
public String ReadFile(String FileName) {
String Name = FileName;
String File = "";

try {
FileReader ReadF = new FileReader(Name);//读文件
BufferedReader HuanChong = new BufferedReader(ReadF);//文件读缓冲.
try {
File = HuanChong.readLine();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
//System.out.println("文件:"+File);
return File;
}
}//ReadFiles class
}//ThreadRun class
}//ToOracle class 
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号