我开发了一个执行 sql 作业的应用程序。当我单击执行按钮时,我的应用程序进入运行状态并暂停,直到执行查询。
我希望我的应用程序不应该停止并且用户应该能够输入其他查询并且这些查询执行应该在后台运行。
我的问题是如何在后台运行查询的执行?意味着当单击执行按钮时,剩余的执行应该在屏幕后面运行。
我的应用程序是使用struts1.3框架开发的。我在Action Class的execute()中编写了主要功能
execute() 的代码片段
DAO dao1=new DAO();
System.out.println("Here...1");
con1=dao1.DBConnection(jndiname);
Statement st = con1.createStatement();
//status_id=1;
ResultSet rs = st.executeQuery(query);
System.out.println("Here...2");
String id = Long.toString(System.currentTimeMillis());
//int req_id = System.currentTimeMillis();
String dirTree= rsBundle.getString("CSV_DIR");
File f=new File(dirTree);
String[] directories = dirTree.split("/");
String[] lists=f.list();
for (String dir : directories )
{
if (!dir.isEmpty() )
{
if (f.exists())
{
System.out.println("directory exist");
}
if (!f.exists())
{
boolean success = (new File(dirTree).mkdirs());
if(success)
{
System.out.println("directory created");
}
}
}
}
for(String s:lists)
{
System.out.println("files.." + s);
}
String csv_file_path=dirTree+"/";
String csv_file_name=id +".csv";
//writing to csv file
CSVWriter writer = new CSVWriter(new FileWriter(csv_file_path + csv_file_name), ',',CSVWriter.NO_QUOTE_CHARACTER);
writer.writeAll(rs, true);
writer.close();
//status_id=7;
String zip_file_path=rsBundle.getString("zip_file_path");
String zip_filename=id + ".zip";
String zip_file_pwd=rsBundle.getString("zip_file_pwd");
//zip file creation
ZipUtil.zipDirWithPassword(dirTree, zip_file_path + zip_filename,zip_file_pwd);
String ftp_file_path=rsBundle.getString("ftp_file_path");
long zip_file_size= new File(zip_file_path + zip_filename).length();
System.out.println("File size..inside" + zip_file_size);
System.out.println("Here...3");
String exec_id=(String)request.getSession().getAttribute("userLoginId");
//int executor_id= Integer.parseInt(exec_id);
DateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
//get current date time with Date()
Date date = new Date();
System.out.println(dateFormat.format(date));
String query4 = "select executor_id,email_id from m_executor where windows_id = '" + exec_id + "'";
System.out.println("Query... " + query4);
//int i=0;
iPreparedStatement4=con.prepareStatement(query4);
iResultSet3=iPreparedStatement4.executeQuery();
while(iResultSet3.next())
{
//restriction=iResultSet2.getString(1);
exec_email=iResultSet3.getString(2);
executor_id=iResultSet3.getInt(1);
}
ValueListForExec db= new ValueListForExec();
String status_name="";
status_name=db.getStatusName(status_id);
if(zip_file_size <= 5242880){
System.out.println("send via email");
/*}
else
{*/
System.out.println("send via FTP");
upload.upload(host, usrname, pwd,zip_file_path + zip_filename, ftp_file_path,zip_filename);
}
String insertquery="{ call sp_process_job (?,?,?,?) }";
cs = con.prepareCall(insertquery.toString());
cs.setString(1,id);
cs.setString(2,host);
cs.setString(3,usrname);
cs.setString(4,pwd);
cs.execute();
con.commit();