在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 明高 阅读(396) 评论(0)  编辑  收藏 所属分类: Lotus


只有注册用户登录后才能发表评论。


网站导航:
 
<2010年4月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

导航

统计

常用链接

留言簿

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜