在Lotus開發中的使用JDBC進行數據交互

          import java.io.*;
          import java.net.URL;
          import java.sql.*;
          import java.util.Properties;
          import lotus.notes.*;
          import java.util.*;

          public class  savetonewdatabase extends AgentBase {
           public void NotesMain() {

            Driver drv = null;
            PrintWriter out = null; 
                 try {
                     Session session = getSession();
                     AgentContext ac = session.getAgentContext();
                     Database db = ac.getCurrentDatabase();
             Database SendDB = session.getDatabase(db.getServer(),"lt_getfile.nsf");
                     Document doc = ac.getDocumentContext();   

                     out = getAgentOutput();      
                         String docUnid;
                         //Get the new record's unid
                         docUnid = uniqueID();
                             
             //Get the sql insert statement   
             StringBuffer SqlUrl = new StringBuffer("Insert into Shouwen_stat (");
             StringBuffer SqlValue = new StringBuffer(" values (");

               String temp= doc.getItemValueString("F_hao");
            
                         if(temp!=null){
                          temp = doc.getItemValueString("F_ziTitle")+"〔"+doc.getItemValueString("F_zi")+"〕"+doc.getItemValueString("F_hao")+"號";
                          }else{
                          temp = "〔"+doc.getItemValueString("F_zi")+"〕";
                         }  
           
             if (temp!= null){
              SqlUrl.append("doc_no");
              SqlValue.append("'" + temp+"'");
               
             }
             String doc_id = doc.getItemValueString("CurDocId");
             if (doc_id != null) {
              SqlUrl.append(",doc_id");
              SqlValue.append(",'" + doc_id + "'");
             }
             String sqlField = doc.getItemValueString("F_title");
             if (sqlField != null) {
              SqlUrl.append(",doc_title");
              SqlValue.append(",'" + sqlField + "'");
              }
             
             sqlField = doc.getItemValueString("shenghr");
             if (sqlField != null) {
              SqlUrl.append(",niban_people");
              SqlValue.append(",'" + sqlField + "'");
             }
             
             sqlField = doc.getItemValueString("F_BigSpecies");
             if (sqlField != null) {
              SqlUrl.append(",wen_zhong");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("text");
             if (sqlField != null) {
              SqlUrl.append(",file_content");
              SqlValue.append(",'" + sqlField  + "'");
             }

             sqlField = doc.getItemValueString("timewrite"); //收文日期
             
             if (sqlField != null) {
              SqlUrl.append(",shouwen_date");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("F_FilekeyWord");
             if (sqlField != null) {
              SqlUrl.append(",title_word");
              SqlValue.append(",'" + sqlField  + "'");
              }
             sqlField = doc.getItemValueString("F_emergency");
             if (sqlField != null) {
              SqlUrl.append(",huan_ji");
              SqlValue.append(",'" + sqlField + "'");
             }
             
             sqlField = doc.getItemValueString("F_UnitName");
             if (sqlField != null) {
              SqlUrl.append(",laiwen_unit");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("F_Secret");
             if (sqlField != null) {
              SqlUrl.append(",mi_ji");
              SqlValue.append(",'" + sqlField  + "'");
              }

             sqlField = doc.getItemValueString("laiwfs");
             if (sqlField != null) {
              SqlUrl.append(",laiwen_mode");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("shengpyj");
             if (sqlField != null) {
              SqlUrl.append(",niban_date");
              SqlValue.append(",'" + sqlField  + "'");
             }
             
             sqlField = doc.getItemValueString("shenghyj");
             if (sqlField != null) {
              SqlUrl.append(",niban_yijian");
              SqlValue.append(",'" + sqlField + "'");
             }
             
             sqlField = doc.getItemValueString("F_EndTime");
             if (sqlField != null) {
              SqlUrl.append(",banli_qixian");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("lind");
             
             if (sqlField != null) {
              SqlUrl.append(",chengban_yj");
              SqlValue.append(",'" + sqlField  + "'");
              }

             sqlField = doc.getItemValueString("pisyj");
             if (sqlField != null) {
              SqlUrl.append(",piban_date");
              SqlValue.append(",'" + sqlField  + "'");
             }
             
             sqlField = doc.getItemValueString("lindps");
             if (sqlField != null) {
              SqlUrl.append(",piban_yijian");
              SqlValue.append(",'" + sqlField  + "'");       
             }

                 sqlField = doc.getItemValueString("banlyj");
             if (sqlField != null) {
              SqlUrl.append(",banli_jieguo");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("banlr");
             if (sqlField != null) {
              SqlUrl.append(",banli_people");
              SqlValue.append(",'" + sqlField  + "'");
             }

             sqlField = doc.getItemValueString("banlsj");
             if (sqlField != null) {
              SqlUrl.append(",banli_date");
              SqlValue.append(",'" + sqlField  + "'");
             }
                         sqlField = doc.getItemValueString("chengbyj");
             if (sqlField != null) {
              SqlUrl.append(",piban_people");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("chengbr");
             if (sqlField != null) {
              SqlUrl.append(",chengban_people");
              SqlValue.append(",'" + sqlField  + "'");
             }

             sqlField = doc.getItemValueString("chengbsj");
             if (sqlField != null) {
              SqlUrl.append(",chengban_date");
              SqlValue.append(",'" + sqlField  + "'");
             }
             sqlField = doc.getItemValueString("temp");  //流水號
             if (sqlField != null) {
              SqlUrl.append(",shouwen_bianhao");
              SqlValue.append(",'" + sqlField  + "'");
             }  
             sqlField=doc.getItemValueString("shihgd");   //文件是否歸檔
            if(sqlField!=null){
             SqlUrl.append(",document_state");
              SqlValue.append(",'"+sqlField+"'");
             } 
             sqlField=doc.getItemValueString("wenjzx");    //文件走向
             if(sqlField!=null){
              SqlUrl.append(",send_file");
              SqlValue.append(",'"+sqlField+"'");
             }   

             SqlUrl.append(")");
             SqlValue.append(")");
             String Va = SqlValue.toString();
              SqlUrl.append(Va);
             
             // Connect to data source
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             drv = new sun.jdbc.odbc.JdbcOdbcDriver();   
             
             String url = "jdbc:odbc:is_archive";
                           
             Properties props = new Properties();
             props.put("user","isa");
             props.put("password","gxmi");   
             Connection con = drv.connect(url,props);
             
             if (con==null){
              out.println("<h1>Con't Connect to DB!</h1>");
              return;
             }   
             Statement stmt = con.createStatement();
             
             //Insert a record to the Fwdj table             
             Va = SqlUrl.toString();
             Va =new String(Va.getBytes("gb2312"),"ISO-8859-1"); 
             
             stmt.executeUpdate(Va);
           
            
                   out.println("<link rel='stylesheet' href='/oa.css'><br><br><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>");
                       out.println("<TR VALIGN=top><TD WIDTH=232><IMG SRC='/Lt_getfile.nsf/c01a1dee4878d8a648256b270024a88c/$Body/0.25E!OpenElement&FieldElemFormat=gif' WIDTH=208 HEIGHT=21></TD>");
                       out.println("<TD WIDTH=416 VALIGN=middle><DIV ALIGN=center><B><FONT SIZE=5 COLOR='0000FF'>操作反饋信息</FONT></B></DIV></TD></TR></TABLE>");
                       out.println("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR VALIGN=top>");
                       out.println("<TD WIDTH=689><IMG SRC='/Lt_getfile.nsf/c01a1dee4878d8a648256b270024a88c/$Body/0.CFA!OpenElement&FieldElemFormat=jpg' WIDTH=688 HEIGHT=4></TD></TR>");
                       out.println("</TABLE><BR><br><br><br><br><P><BR><BR><BR><BR>");
                       out.println("<table border=0  bgColor=#0099cc borderColorLight=#000000 cellPadding=1 cellSpacing=2 align='center'><tr><td  bgcolor=#EFEFEF>文件發送給下一辦理人"+doc.getItemValue("sendtobak")+"辦理!</td></tr></table>");
           
            } catch (Exception e) {
             out.println(e.getMessage());
             e.printStackTrace();
            }
              }
           public static String uniqueID()
            {
                   StringBuffer sb=new StringBuffer(20);
               java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy/MM/dd");
               java.util.Date currentTime=new java.util.Date();
               String sid=formatter.format(currentTime);
               return sid;
               }
              
           public static String replaceAll(String operStr,String oldStr ,String replaceStr){
            int fromIndex=0;
            int index=0;
            int oldStrLen=oldStr.length();
            int replaceStrLen=replaceStr.length();
            
            while((index=operStr.indexOf(oldStr,fromIndex))!=-1){
             //新的位置起點
             //fromIndex+replaceStrLen-oldStrLen+1
             fromIndex=index + replaceStrLen;
             operStr=operStr.substring(0,index)+replaceStr+
              operStr.substring(index+oldStrLen,operStr.length());
            }
            
            return operStr;
           }
           
           
           
          }

          posted on 2010-04-09 09:20 明高 閱讀(403) 評論(0)  編輯  收藏 所屬分類: Lotus

          <2010年4月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          導航

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 仙桃市| 吉木乃县| 边坝县| 民县| 景东| 长岛县| 井研县| 菏泽市| 沙湾县| 烟台市| 方城县| 姚安县| 永平县| 囊谦县| 东乌珠穆沁旗| 连南| 浮梁县| 田阳县| 桂平市| 内乡县| 宝清县| 朔州市| 疏附县| 东光县| 若羌县| 昂仁县| 高密市| 响水县| 广河县| 邓州市| 抚宁县| 剑阁县| 尚志市| 弥勒县| 台州市| 望城县| 都兰县| 吉木萨尔县| 昌邑市| 肇庆市| 平武县|