程序可以实现插入,但是有时会等很长时间,甚至有时一直处于等待。我想请教一下各位是否有效率更高的方法?
我的程序如下:
//*********************************************
import java.sql.*;
import java.io.*;
public class DBdo{
public boolean insert(String startdate,String filename) throws IOException, SQLException{
boolean flag=false;
DBCon dbcon=new DBCon();//DBCon是连接数据库的,返回conn.
Connection conn=dbcon.getCon();
conn.setAutoCommit(false);
Statement stmt=conn.createStatement();

String strsql="insert into mytable values (to_date('"+startdate+"','yyyymmdd'),EMPTY_CLOB())";
stmt.executeUpdate(strsql);
String strsql1="select obsvalue from mytable where (startdate=to_date('"+startdate+"','yyyymmdd')) for update";
ResultSet rs=stmt.executeQuery(strsql1);

File f=new File(obsvalue);
if(f.exists()){
while(rs.next()){
Object obj=rs.getClob("obsvalue");
oracle.sql.CLOB clob=(oracle.sql.CLOB)obj;
BufferedWriter out=
new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in=
new BufferedReader(new FileReader(filename));
int c;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
conn.commit();
}

flag=true;
rs.close();
stmt.close();
dbcon.closeCon();
return flag;
}

public static void main(String[] args) throws IOException {
DBdo dbapp=new DBdo();
try {
dbapp.insert("20080405","temp.txt");
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("完成!");
}
}
//********************************