九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
EXCEL導(dǎo)入數(shù)據(jù)庫及數(shù)據(jù)庫數(shù)據(jù)導(dǎo)出到EXCEL - @家軍-天行鍵,君子以自強(qiáng)不息! -...

EXCEL導(dǎo)入數(shù)據(jù)庫及數(shù)據(jù)庫數(shù)據(jù)導(dǎo)出到EXCEL

關(guān)鍵字: 報(bào)表、jel
   很久沒有發(fā)BLOG,呵呵,是因?yàn)樽罱趲椭笥言谧鲆粋€(gè)項(xiàng)目,很忙。呵呵,我覺得生活就應(yīng)該是這樣,年輕時(shí)候的忙碌是為年老時(shí)候的悠閑吧。
   主要涉及內(nèi)容及技術(shù):
  javaexcel api
  jasonreport及編輯工具ireport和數(shù)據(jù)庫技術(shù)。
 導(dǎo)入及導(dǎo)出EXCEL解決思路:
  使用javaexcel api導(dǎo)入普通的EXCEL表格,就是沒有合并單元格的規(guī)范數(shù)據(jù),如果導(dǎo)出有規(guī)則的EXCEL也使用JAVAEXECEL API,對(duì)中文支持比較好。
  如果要導(dǎo)出報(bào)表可打印的EXCEL,使用ireport為工具圖形化畫出報(bào)表,并使用jasonreprt控制導(dǎo)出,展示給客戶端。
  主要代碼有:
  連接數(shù)據(jù)庫的方法:
java 代碼
 
  1. import java.sql.Connection;  
  2. import java.sql.ResultSet;  
  3. import java.sql.SQLException;  
  4. import java.sql.Statement;  
  5. import java.util.Hashtable;  
  6. import java.util.Vector;  
  7.   
  8. import org.apache.log4j.Logger;  
  9.   
  10. public class DBOperate {     
  11.       
  12.     /** 
  13.      * 得到sequence的nextval 
  14.      * @param sequenceName  
  15.      * @return 
  16.      */  
  17.     public static String getSequence(String sequenceName) {  
  18.         String nextval = "";  
  19.         if(sequenceName == null || "".equals(sequenceName)) {  
  20.             System.out.println("sequenceName name is null!");             
  21.             return null;  
  22.         } else {  
  23.             sequenceName = sequenceName.toUpperCase();            
  24.             String sql = "select " + sequenceName + ".nextval nextid from user_sequences where sequence_name = '"   
  25.                        + sequenceName + "'";  
  26.               
  27.             Statement stmt = null;  
  28.             Connection conn = null;  
  29.             ResultSet rs = null;  
  30.               
  31.             try {  
  32.                 conn = TreatDB.getConnDB("");  
  33.                 if (conn != null) {  
  34.                     stmt = conn.createStatement();  
  35.                     rs = stmt.executeQuery(sql);  
  36.                       
  37.                     if(rs != null) {  
  38.                       while(rs.next()) {  
  39.                         nextval = rs.getString("nextid");                         
  40.                       }  
  41.                     }  
  42.                 }  
  43.             } catch (SQLException e) {  
  44.                 System.out.println("SQLException : " + e);  
  45.             } finally {  
  46.                 try {  
  47.                     if(rs != null) rs.close();  
  48.                     if(stmt != null) stmt.close();  
  49.                     if(conn != null) conn.close();  
  50.                 } catch (SQLException e) {  
  51.                     // TODO Auto-generated catch block                    
  52.                 }  
  53.             }  
  54.             return nextval;  
  55.         }  
  56.     }  
  57. /** 
  58.      * 一個(gè)插入、更新數(shù)據(jù)表的通用方法,傳入一個(gè)sql腳本 
  59.      * @param sql :要進(jìn)行操作的腳本 
  60.      * @return :發(fā)生變化的條數(shù) 
  61.      */  
  62.     public static int updateSql(String sql) {  
  63.         String dbName = "";  
  64.         Connection conn = null;  
  65.         Statement stmt = null;  
  66.         int result = 0;  
  67.         try {  
  68.             conn = TreatDB.getConnDB(dbName);  
  69.             if (conn != null) {  
  70.                 stmt = conn.createStatement();  
  71.                 //logger.info(sql);  
  72.                 result = stmt.executeUpdate(sql);                 
  73.                 conn.commit();  
  74.             }  
  75.   
  76.         } catch (SQLException e) {  
  77.             try {  
  78.                 conn.rollback();  
  79.             } catch (SQLException e1) {  
  80.                 System.out.println("update sql error: "+e);  
  81.                   
  82.             }             
  83.             System.out.println("update sql error: "+e);  
  84.             System.out.println("sql: " + sql);            
  85.         } finally {  
  86.             try {  
  87.                 if (stmt != null)  
  88.                     stmt.close();  
  89.                 if (conn != null)  
  90.                     conn.close();  
  91.             } catch (Exception ex) {  
  92.                 //do nothing;  
  93.             }  
  94.   
  95.         }  
  96.         return result;  
  97.     }  
  98.       
  99. }  
導(dǎo)入EXCEL的程序代碼:
java 代碼
 
  1. /** 
  2.      * 將Excel文件中的數(shù)據(jù)添加到數(shù)據(jù)庫中 
  3.      * 新的監(jiān)理信息 modify by heweiya 
  4.      *  
  5.      * @param xlsFile,Excel文件 
  6.      * @return 
  7.      */  
  8.     public String addJLXlsForm(InputStream is) {  
  9.           
  10.         String errStr = "";  
  11.         String result = "";       
  12.   
  13.         try {             
  14.             Workbook rwb = Workbook.getWorkbook(is);  
  15.             // Workbook rwb = Workbook.getWorkbook(new File(filePath+fileName));  
  16.             // 獲取第一張Sheet表  
  17.             Sheet sheet = rwb.getSheet(0);  
  18.             // 獲取總列數(shù)  
  19.             int rsColumns = sheet.getColumns();  
  20.             System.out.println("rsColumns = " + rsColumns);  
  21.               
  22.             // 獲取總行數(shù)  
  23.             int rsRows = sheet.getRows();  
  24.             System.out.println("rsRows = " + rsRows);  
  25.               
  26.             if (rsColumns < 19) {  
  27.                 errStr = "錯(cuò)誤原因:字段不全。";  
  28.                 vErr.addElement(errStr);  
  29.             }  
  30.               
  31.             int i = 0;  
  32.             int startRows = 1;  
  33.             int startColumn = 0;  
  34.             while (startRows < rsRows) {  
  35.                 Hashtable ht = new Hashtable();  
  36.                   
  37.                 String zj_id = DBOperate.getSequence("S_JIANLI");         
  38.   
  39.                   
  40.                 Cell tmp = sheet.getCell(0,startRows);                    
  41.                 String sfzh = tmp.getContents();      
  42.                   
  43.                 tmp = sheet.getCell(1,startRows);                     
  44.                 String issueDate = tmp.getContents();                 
  45.                 String issueDate_new = "";  
  46.                 if(issueDate != null && issueDate.length()>=6) issueDate_new = issueDate.substring(6) + issueDate.substring(3,5) + issueDate.substring(0,2);  
  47.                   
  48.                 tmp = sheet.getCell(2,startRows);                     
  49.                 String approveDate = tmp.getContents();               
  50.                 String approve_date_new = "";  
  51.                 if(approveDate != null && approveDate.length()>=6) approve_date_new = approveDate.substring(6) + approveDate.substring(3,5) + approveDate.substring(0,2);  
  52.               
  53.                 tmp = sheet.getCell(3,startRows);                     
  54.                 String cerNo = tmp.getContents();  
  55.                   
  56.                 tmp = sheet.getCell(4,startRows);                     
  57.                 String jianliMajor = tmp.getContents();               
  58.   
  59.                 tmp = sheet.getCell(5,startRows);                     
  60.                 String department = tmp.getContents();  
  61.                   
  62.                 tmp = sheet.getCell(6,startRows);                     
  63.                 String jianliName = tmp.getContents();  
  64.               
  65.                 tmp = sheet.getCell(7,startRows);                     
  66.                 String jianliSex = tmp.getContents();                         
  67.                   
  68.                 //畢業(yè)院校  
  69.                 tmp = sheet.getCell(8,startRows);                     
  70.                 String degree = tmp.getContents();  
  71.               
  72.                 //畢業(yè)時(shí)間  
  73.                 tmp = sheet.getCell(9,startRows);                     
  74.                 String cooleage = tmp.getContents();  
  75.               
  76.                 //所學(xué)專業(yè)  
  77.                 tmp = sheet.getCell(10,startRows);                    
  78.                 String company = tmp.getContents();  
  79.               
  80.                 //職務(wù)  
  81.                 tmp = sheet.getCell(11,startRows);                    
  82.                 String tech_post = tmp.getContents();                 
  83.                   
  84. //              工作單位  
  85.                 tmp = sheet.getCell(12,startRows);                    
  86.                 String address = tmp.getContents();               
  87.                   
  88. //              職稱  
  89.                 tmp = sheet.getCell(13,startRows);                    
  90.                 String postcode = tmp.getContents();                  
  91.                   
  92.                 tmp = sheet.getCell(14,startRows);                    
  93.                 String jianliTel = tmp.getContents();  
  94.                   
  95.                 tmp = sheet.getCell(15,startRows);                    
  96.                 String mobile = tmp.getContents();  
  97.                   
  98.                 tmp = sheet.getCell(16,startRows);                    
  99.                 String email = tmp.getContents();  
  100.                   
  101.                 tmp = sheet.getCell(17,startRows);                    
  102.                 String birthday = tmp.getContents();                  
  103.                 String birthday_new = "";  
  104.                 if(birthday != null && birthday.length()>=6) birthday_new = birthday.substring(6) + birthday.substring(3,5) + birthday.substring(0,2);  
  105.                   
  106.                   
  107.                 tmp = sheet.getCell(18,startRows);                    
  108.                 String jianli_type = tmp.getContents();   
  109.                 //加入密碼 modify by heweiya 2007/05/17  
  110.                 String sql = "insert into jianli values('" + zj_id + "', '" + sfzh + "', to_date('" + issueDate_new + "','yyyymmdd'),to_date('"  
  111.                    + approve_date_new + "','yyyymmdd'),'" + cerNo + "','" + jianliMajor + "','" + department + "','"  
  112.                    + jianliName + "','" + jianliSex + "','" + degree + "','" + cooleage + "','"   
  113.                    + company + "','" + tech_post + "','" + address + "','" + postcode + "','" + jianliTel   
  114.                    + "','" + mobile + "','" + email + "',to_date('" + birthday_new + "','yyyymmdd'),'" + jianli_type  + "',null,null,null,null,"+sfzh.substring(010)+",null,null,null,null,null)";  
  115.                   
  116.                 int a = DBOperate.updateSql(sql);  
  117.                   
  118.                 System.out.println("成功導(dǎo)入第"+startRows+"條");        
  119.                 if (a == 0) {  
  120.                     errStr = errStr + "添加失敗:庫中已有此記錄,或有值不符合庫中設(shè)定的字段屬性!";  
  121.                 } else if (a == 1) {  
  122.                     result = "添加成功";  
  123.                 } else {  
  124.                     errStr = errStr + "添加失敗:連接數(shù)據(jù)庫失敗";  
  125.                 }  
  126.                       
  127.                   
  128.   
  129.                 if (!"".equals(errStr)) {  
  130.                     vErr.addElement("導(dǎo)入:" + "【" + startRows + "】" + "<br>(錯(cuò)誤原因:" + errStr);  
  131.                     errStr += "導(dǎo)入:" + "【" + startRows + "】" + "<br>(關(guān)鍵字段為:姓名:"+jianliName+",身份證號(hào)為:"+sfzh+",監(jiān)理證書號(hào)為:"+cerNo+")<br>";  
  132.                 } else {  
  133.                     vOk.add(ht);  
  134.                 }  
  135.   
  136.                 startRows++;  
  137.             }  
  138.               
  139.             rwb.close();  
  140.             result = "成功導(dǎo)入:" + vOk.size()+"條記錄。<br> 錯(cuò)誤導(dǎo)入: " + vErr.size()+"條記錄,錯(cuò)誤記錄及原因如下:<br>"+errStr;  
  141.             System.out.println("vOK.size() = " + vOk.size());  
  142.             System.out.println("VErr.size() = " + vErr.size());  
  143.             return result;  
  144.         } catch (Exception e) {  
  145.             result = "在導(dǎo)入的過程當(dāng)中發(fā)生了錯(cuò)誤,其中錯(cuò)誤的原因是:" + e.toString();            
  146.             return result;  
  147.         }  
  148.     }  
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JSP中早就有了類似.Net DataSet那樣的離線數(shù)據(jù)訪問了,拋棄ResultSet,擁抱Result吧!
Myeclipse連接mysql數(shù)據(jù)庫(給力的寫)全程心得)
用java調(diào)用oracle存儲(chǔ)過程總結(jié) 3 - 返回列表-偶愛老婆-搜狐博客
JComboBox中放入訪問數(shù)據(jù)庫所得內(nèi)容
java程序連接ORACLE 10g 數(shù)據(jù)庫與操作
Sqlserver 實(shí)現(xiàn)跨數(shù)據(jù)庫,跨服務(wù)器,表結(jié)構(gòu)不同 導(dǎo)入數(shù)據(jù)
更多類似文章 >>
生活服務(wù)
熱點(diǎn)新聞
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服