PageRenderTime 17ms CodeModel.GetById 6ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/webccr/src/com/emis/caesar/emisCommonExcelWriteTask.java

https://bitbucket.org/sanliou/synccr
Java | 75 lines | 52 code | 18 blank | 5 comment | 1 complexity | 81e7086e5fb1055a2af1a1b26b1dd14a MD5 | raw file
 1package com.emis.caesar;
 2
 3import java.sql.ResultSet;
 4import java.sql.ResultSetMetaData;
 5
 6import javax.servlet.ServletContext;
 7
 8
 9
10import com.emis.db.emisConnection;
11import com.emis.db.emisDb;
12import com.emis.db.emisDbRun;
13import com.emis.file.emisExcelWriter;
14import com.emis.file.emisFile;
15import com.vaadin.ui.UI;
16
17public class emisCommonExcelWriteTask  extends emisProgressTask {
18
19	String m_SQL; 
20	String m_fileName;
21	final emisProgressTask thisTask = this;
22	
23	public emisCommonExcelWriteTask(ServletContext application , UI ui, String sSQL , String fileName ) {
24		super(application,ui);
25		m_SQL=sSQL;
26		m_fileName = fileName;
27	}
28	
29	@Override
30	public void run() {
31		
32		try {
33			
34			//thisTask.setStatus("start");
35
36			final emisExcelWriter eew = new emisExcelWriter( m_fileName );
37			eew.createSheet("eprint");
38			emisDb.getInstance().execute(new emisDbRun() {
39				@Override
40				public Object run(emisConnection c) throws Exception {
41					
42					ResultSet rs = c.createStatement().executeQuery(m_SQL);
43					ResultSetMetaData meta = rs.getMetaData();
44					int columnCount = meta.getColumnCount();
45					Object [] row = new Object[columnCount];
46					int statusCnt = 0;
47					int iRows = 0;
48					while( rs.next() ) {
49						for(int i=1;i<=columnCount;i++) {
50							row[i-1]=rs.getString(i);
51						}
52						
53						eew.writeRow(row);
54						statusCnt++;
55						iRows++;
56						//if(statusCnt > 1000) {
57						//	statusCnt = 0;
58							thisTask.setStatus("writing " +iRows);
59						//}
60					}
61					return null;
62				}
63				
64			});
65			eew.close();
66			thisTask.setStatus("Complete");
67		
68		} catch (Exception e) {
69//			emisLog.error(emisCommonExcelWriteTask.class, e);
70      e.printStackTrace();
71		}
72		
73	}
74
75}