domino采用JDBC与关系数据库集成

本文介绍Domino如何通过JDBC与Oracle数据库集成,包括增删改操作的具体实现方式,并提供了测试连接、查询、删除和更新数据的Java示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

domino采用JDBC与关系数据库集成

  439人阅读  评论(0)  收藏  举报
  分类:

       domino是文档型数据库,相比关系数据库在权限控制方便有一定的优势,但是在数据分析、统计方面在关系数据库面前则是它的瓶颈。故在实施数据分析、统计方面的应用与关系数据库集成则成为了必然。

       本文的项目背景是实现流程效率统计,通过此应用来监控流程各个环节的办理情况,超过办理时限的环节通过绩效扣分的方式来进行管控,达到有效提高流程的办理效率。

       流程审批平台:domino

       数据存储:Oracle

       数据分析、统计:tomcat+servlet

       这里主要讲domino怎样往oracle进行增、删、改动作。

【jar包】

       ojdbc14.jar (网上很多,找起来也方便,部署在\jvm\lib\ext目录下,要重启domino)

Java脚本库】

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. import java.sql.Connection;  
  2. import java.sql.DriverManager;  
  3. import java.sql.ResultSet;  
  4. import java.sql.Statement;  
  5.   
  6. public class HurrylogClass {   
  7.       
  8.     Connection conn = null;  
  9.     Statement stmt = null;  
  10.     ResultSet rset = null;  
  11.       
  12.     String sDriver = "";  
  13.     String sURL = "";  
  14.     String sName = "";  
  15.     String sPasswd = "";  
  16.       
  17.     /* 
  18.      * 构造函数 
  19.      */  
  20.     public HurrylogClass() throws Exception{  
  21.           
  22.     }  
  23.       
  24.     public void fnSetSDriver(String sDriver){  
  25.         this.sDriver = sDriver;  
  26.     }  
  27.       
  28.     public void fnSetSURL(String sURL){  
  29.         this.sURL = sURL;  
  30.     }  
  31.       
  32.     public void fnSetSName(String sName){  
  33.         this.sName = sName;  
  34.     }  
  35.       
  36.     public void fnSetSPasswd(String sPasswd){  
  37.         this.sPasswd = sPasswd;  
  38.     }  
  39.       
  40.     /* 
  41.      * @初始化 
  42.      */  
  43.     public void fnInit() throws Exception{  
  44.         try{  
  45.             conn = fnInitConnetion();  
  46.         }catch(Exception e){  
  47.             e.printStackTrace();  
  48.         }  
  49.     }  
  50.     /* 
  51.      * @创建与Oracle数据库连接  
  52.      */  
  53.     public Connection fnInitConnetion() throws Exception{  
  54. //      Connection conn = null;  
  55.           
  56.         /*Class.forName("oracle.jdbc.driver.OracleDriver"); 
  57.         conn = DriverManager.getConnection( 
  58.                 "jdbc:oracle:thin:@10.3.255.175:1521:orcl", "hurrylog", 
  59.                 "hurrylog");*/  
  60.         Class.forName(this.sDriver);  
  61.         conn = DriverManager.getConnection(this.sURL, this.sName,this.sPasswd);  
  62.           
  63.         return conn;  
  64.     }  
  65.       
  66.     /* 
  67.      * @创建Statement对象 
  68.      */  
  69.     public Statement fnCreateStatement() throws Exception{  
  70.         try{  
  71. //          conn = fnInitConnetion();  
  72.             if(conn!=null && conn.isClosed()==false){  
  73.                 stmt = conn.createStatement();  
  74.             }  
  75.         }catch(Exception e){  
  76.             e.printStackTrace();  
  77.         }  
  78.         return stmt;  
  79.     }  
  80.     /* 
  81.      * @执行Oracle查询,返回查询结果 
  82.      */  
  83.     public ResultSet fnExcuteQuery(String sQuery) throws Exception{  
  84.           
  85.         try{  
  86. //          conn = fnInitConnetion();  
  87.             if(stmt!=null){  
  88. //              stmt = conn.createStatement();  
  89.                 rset = stmt.executeQuery(sQuery);  
  90.             }  
  91.         }catch(Exception e){  
  92.             e.printStackTrace();  
  93.         }  
  94.         return rset;  
  95.     }  
  96.       
  97.     /* 
  98.      * @执行Oracle数据更新、删除 
  99.      */  
  100.     public int fnExcuteUpdate(String sQuery) throws Exception{  
  101.         int bReturn=0;  
  102.         try{  
  103. //          conn = fnInitConnetion();  
  104.             if(stmt!=null){  
  105. //              stmt = conn.createStatement();  
  106.                 bReturn = stmt.executeUpdate(sQuery);  
  107.             }  
  108.         }catch(Exception e){  
  109.             e.printStackTrace();  
  110.         }  
  111.         return bReturn;  
  112.     }  
  113.       
  114.     /* 
  115.      * @关闭conn、stmt、rset对象 
  116.      */  
  117.     public void fnCloseObject() throws Exception{  
  118.         try {  
  119.             if(rset!=null){  
  120.                 rset.close();  
  121.             }  
  122.             if(stmt!=null){  
  123.                 stmt.close();  
  124.             }  
  125.             if(conn!=null){  
  126.                 conn.close();  
  127.             }                 
  128.         } catch (Exception e) {  
  129.             e.printStackTrace();  
  130.         }  
  131.     }  
  132. }  

【oracel测试连接代码(参考)】

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. import lotus.domino.*;  
  2.   
  3. import java.io.PrintWriter;  
  4. import java.sql.Connection;  
  5.   
  6. public class JavaAgent extends AgentBase {  
  7.     Connection conn = null;  
  8.     HurrylogClass hurry = null;  
  9.     Session ss = null;  
  10.     AgentContext agt = null;  
  11.     Database db = null;  
  12.     Document proDoc = null;  
  13.       
  14.     PrintWriter pw = null;  
  15.       
  16.     String sDriver = "";  
  17.     String sURL = "";  
  18.     String sName = "";  
  19.     String sPasswd = "";  
  20.     public void NotesMain() {  
  21.         try {  
  22.             pw = getAgentOutput();  
  23.               
  24.             ss = getSession();  
  25.             agt = ss.getAgentContext();  
  26.             db = agt.getCurrentDatabase();  
  27.             proDoc = db.getProfileDocument("ConfigProfile",null);  
  28.             if(proDoc!=null){  
  29.                 sDriver = proDoc.getItemValueString("jdbcDriver");  
  30.                 sURL = proDoc.getItemValueString("jdbcURL");  
  31.                 sName = proDoc.getItemValueString("jdbcUsername");  
  32.                 sPasswd = proDoc.getItemValueString("jdbcPassword");  
  33. //              System.out.println("sDriver=>"+sDriver+"<");  
  34. //              System.out.println("sURL=>"+sURL+"<");  
  35. //              System.out.println("sName=>"+sName+"<");  
  36. //              System.out.println("sPasswd=>"+sPasswd+"<");  
  37. //              初始化jdbc类  
  38.                 hurry = new HurrylogClass();  
  39. //              初始化jdbc参数  
  40.                 hurry.fnSetSDriver(sDriver);  
  41.                 hurry.fnSetSURL(sURL);  
  42.                 hurry.fnSetSName(sName);  
  43.                 hurry.fnSetSPasswd(sPasswd);  
  44. //              创建jdbc连接  
  45.                 conn = hurry.fnInitConnetion();  
  46.                 if(conn!=null){  
  47.                     pw.println("<script>alert('oracle连接成功!');history.back();</script>");  
  48.                 }else{  
  49.                     pw.println("<script>alert('oracle连接失败,请检查配置!');</script>");  
  50.                 }  
  51.             }else{  
  52.                 pw.println("<script>alert('请进行JDBC参数配置!');</script>");  
  53.             }  
  54.         } catch (Exception e) {  
  55.             e.printStackTrace();  
  56.         } finally {  
  57.             try {  
  58.                 if(pw!=null){  
  59.                     pw.close();  
  60.                 }  
  61.                 hurry.fnCloseObject();  
  62.                 if(conn!=null){  
  63.                     conn.close();  
  64.                 }     
  65.                 if(proDoc!=null){  
  66.                     proDoc.recycle();  
  67.                 }  
  68.                 if(db!=null){  
  69.                     db.recycle();  
  70.                 }  
  71.                 if(agt!=null){  
  72.                     agt.recycle();  
  73.                 }  
  74.                 if(ss!=null){  
  75.                     ss.recycle();  
  76.                 }  
  77.             } catch (Exception e) {  
  78.                 e.printStackTrace();  
  79.             }  
  80.         }  
  81.     }  
  82.   
  83. }  

【sql查询代码(参考)】

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. public boolean fnCheckOracleData() throws Exception{  
  2.         boolean bReturn=false;  
  3.           
  4. //      HurrylogClass hurry = new HurrylogClass();  
  5.         ResultSet rs = null;  
  6.           
  7.         Database appDb = null;  
  8.         Document appDoc = null;       
  9.           
  10.         Document logDoc = null;       
  11. //      Database orgDb = null;  
  12. //      View orgView = null;  
  13. //      Document orgDoc = null;  
  14.         Vector oDept = null;  
  15.           
  16.         String sDeptName = "";  
  17.         int iCount = 0;  
  18.         long rsCount = 0;  
  19.           
  20.   
  21.         String sQuery = "";  
  22.         String sHurrylogUNID = "";  
  23.         String sAppDocUNID = "";  
  24.         String sAppDbpath = "";  
  25.         String sTitle = "";  
  26.         String sCurUser = "";  
  27.         String sCurDept = "";  
  28.         String sInTime = "";  
  29.         String sIsOverTime = "";  
  30.         try {  
  31.             //遍历oracle数据前,清除未处理日志,重新生成  
  32.             undealView.getAllEntries().removeAll(true);  
  33. //          获取当前年份  
  34.             Calendar cal = Calendar.getInstance();  
  35.             int year = cal.get(Calendar.YEAR);  
  36. //          year = 2013;  
  37.             if(hurrylogDb.isOpen()){  
  38.                 sQuery = "select DOCID,V_DOCID,V_PATH,V_TITLE,V_CURRENT_USER,V_DEPARTMENT,V_IN_TIME,ISOVERTIME from t_hurrylog t where t.v_in_time >= to_date('"+year+"-01-01', 'yyyy-mm-dd') and t.v_in_time < to_date('"+(year+1)+"-01-01', 'yyyy-mm-dd')";  
  39. //              System.out.println("sQuery=="+sQuery);  
  40.                 rs = hurry.fnExcuteQuery(sQuery);  
  41.                   
  42. //              循环oracle数据  
  43.                 while(rs.next()){  
  44.                     rsCount = rsCount + 1;  
  45. //                  System.out.println("执行第" + rsCount + "条数据");  
  46.                       
  47.                     sHurrylogUNID = rs.getString(1);  
  48.                     sAppDocUNID = rs.getString(2);  
  49.                     sAppDbpath = rs.getString(3);  
  50.                     sTitle = rs.getString(4);  
  51.                     sCurUser = rs.getString(5);  
  52.                     sCurDept = rs.getString(6);  
  53.                     sInTime = rs.getString(7);  
  54.                     sIsOverTime = rs.getString(8);  
  55.   
  56.                 }  
  57.                 System.out.println("执行完成" + rsCount + "条数据");  
  58.                 //执行结束,返回true  
  59.                 bReturn = true;  
  60.             }         
  61.               
  62.   
  63.         } catch (Exception e) {  
  64.             e.printStackTrace();  
  65.         }finally{  
  66. //          关闭oracle连接,domino相关对象  
  67.               try{  
  68. //                hurry.fnCloseObject();  
  69.                   if(rs!=null){  
  70.                       rs.close();  
  71.                   }  
  72.                   if(appDoc!=null){  
  73.                       appDoc.recycle();  
  74.                   }  
  75.                   if(logDoc!=null){  
  76.                       logDoc.recycle();  
  77.                   }  
  78.                   if(appDb!=null){  
  79.                       appDb.recycle();  
  80.                   }  
  81.                                     
  82.               }catch(Exception e){  
  83.                   e.printStackTrace();   
  84.               }         
  85.           }  
  86.         return bReturn;  
  87.     }  

【sql删除代码(参考)】

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /* 
  2.      * 处理oracle数据  
  3.      */  
  4.     public boolean fnDealOracleData() throws Exception{  
  5.         boolean bReturn=false;  
  6.           
  7. //      初始化jdbc访问类  
  8. //      HurrylogClass hurry = new HurrylogClass();  
  9.           
  10. //      View undealView = null;  
  11.         Document logDoc = null;  
  12.         Document tmpDoc = null;  
  13.                   
  14.         Vector oDept = null;  
  15.           
  16.         String sHashurry = "";  
  17.         String sType = "";  
  18.         String sHurrylogUNID = "";  
  19.         String sUsername = "";  
  20.         String sCurDept = "";  
  21.         String sOrgDept = "";  
  22.         String sQuery = "";  
  23.           
  24.         int iMark = 0;  
  25.         int iQueryReturn = 0;  
  26.         long rsCount = 0;  
  27.         try{              
  28.           
  29.             undealView = curDb.getView("undealView");  
  30.             logDoc = undealView.getFirstDocument();  
  31.             while(logDoc!=null){  
  32.                 rsCount++;  
  33. //              System.out.println("执行第" + rsCount + "条数据");  
  34.                 iQueryReturn = 0;  
  35.                   
  36.                 tmpDoc = undealView.getNextDocument(logDoc);  
  37.                 sHashurry = logDoc.getItemValueString("hasHurry");  
  38.                 sType = logDoc.getItemValueString("type");  
  39.                 sHurrylogUNID = logDoc.getItemValueString("docid");  
  40.                   
  41. //              1:应用库文档不存在  
  42.                 if(sType.equals("1")||sType.equals("4")||sType.equals("5")){                      
  43. //                  删除oracle数据  
  44.                     sQuery = "delete from t_hurrylog t where t.docid='" + sHurrylogUNID + "'";  
  45.                     iQueryReturn = hurry.fnExcuteUpdate(sQuery);  
  46.                     if(iQueryReturn==1){                          
  47.                         sHashurry = logDoc.getItemValueString("hasHurry");  
  48.                         if(sHashurry.equals("1")){  
  49. //                          删除hurrylog数据  
  50.                             hurrylogDoc = fnGetDocumentByUNID(hurrylogDb,sHurrylogUNID);  
  51.                             if(hurrylogDoc!=null){  
  52.                                 hurrylogDoc.remove(true);  
  53.                             }  
  54.                         }  
  55. //                      日志标记为已处理  
  56.                         logDoc.replaceItemValue("isDone""1");  
  57.                         logDoc.save(true);  
  58.                     }else{  
  59.                         System.out.println(sHurrylogUNID+"删除失败");  
  60.                     }  
  61.                       
  62.                 }  
  63.   
  64. //              文档指向下一条  
  65.                 logDoc = tmpDoc;  
  66.             }  
  67.             System.out.println("执行完成" + rsCount + "条数据");  
  68. //          执行成功返回 true  
  69.             bReturn = true;  
  70.         }catch(Exception e){  
  71.             e.printStackTrace();  
  72.         }finally{  
  73.             try{  
  74.                 if (logDoc != null) {  
  75.                     logDoc.recycle();  
  76.                 }  
  77.                 if (tmpDoc != null) {  
  78.                     tmpDoc.recycle();  
  79.                 }  
  80.             }catch(Exception e){  
  81.                 e.printStackTrace();  
  82.             }  
  83.         }  
  84.         return bReturn;  
  85.     }  

【sql更新代码(参考)】

  

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. import java.io.PrintWriter;  
  2.   
  3. import lotus.domino.*;  
  4.   
  5. public class JavaAgent extends AgentBase {  
  6.   
  7.     Session ss = null;  
  8.     AgentContext agentContext = null;  
  9.     Database curDb = null;  
  10.     Document proDoc = null;  
  11.     Database hurrylogDb = null;  
  12.     Document hurrylogDoc = null;  
  13.     Document curDoc = null;  
  14.       
  15.     PrintWriter pw = null;  
  16.       
  17. //  初始化jdbc访问类  
  18.     HurrylogClass hurry = null;  
  19.       
  20. //  待增加服务器配置项  
  21.     String sOAServer = "";  
  22.     String sHurrylogDbpath = "";  
  23.     String sOrgDbpath = "";  
  24.     String sDriver = "";  
  25.     String sURL = "";  
  26.     String sName = "";  
  27.     String sPasswd = "";  
  28.     String sQuery = "";  
  29.     String sCurDept = "";  
  30.     String sHurrylogUNID = "";  
  31.     public void NotesMain() {  
  32.   
  33.       try {  
  34.           pw = getAgentOutput();  
  35.             
  36.             ss = getSession();  
  37.             agentContext = ss.getAgentContext();  
  38.             curDb = agentContext.getCurrentDatabase();  
  39.             curDoc = agentContext.getDocumentContext();  
  40.             proDoc = curDb.getProfileDocument("ConfigProfile",null);  
  41.             if(proDoc!=null){  
  42.                 sOAServer = proDoc.getItemValueString("OAServer");  
  43.                 sHurrylogDbpath = proDoc.getItemValueString("hurrylogDbpath");  
  44.                 sOrgDbpath = proDoc.getItemValueString("orgDbpath");  
  45.                 sDriver = proDoc.getItemValueString("jdbcDriver");  
  46.                 sURL = proDoc.getItemValueString("jdbcURL");  
  47.                 sName = proDoc.getItemValueString("jdbcUsername");  
  48.                 sPasswd = proDoc.getItemValueString("jdbcPassword");  
  49.             }else{  
  50.                 System.out.println("没有参数配置文档!");  
  51.             }  
  52.               
  53. //          公文效率监督库  
  54. //          hurrylogDb = ss.getDatabase(sOAServer,"chtweboa/system/hurrylog.nsf");  
  55.             hurrylogDb = ss.getDatabase(sOAServer,sHurrylogDbpath);  
  56.             if(hurrylogDb.isOpen()==false){  
  57.                 hurrylogDb.open();  
  58.             }  
  59.                           
  60. //          定义jdbc访问类  
  61.             hurry = new HurrylogClass();  
  62. //          连接参数赋值  
  63.             hurry.fnSetSDriver(sDriver);  
  64.             hurry.fnSetSURL(sURL);  
  65.             hurry.fnSetSName(sName);  
  66.             hurry.fnSetSPasswd(sPasswd);  
  67. //          初始化jdbc类  
  68.             hurry.fnInit();  
  69. //          创建Statement  
  70.             hurry.fnCreateStatement();  
  71.             sCurDept = curDoc.getItemValueString("v_realdept");  
  72.             sHurrylogUNID = curDoc.getItemValueString("DOCID");  
  73.             sQuery = "update t_hurrylog set V_DEPARTMENT='"+sCurDept+"' where DOCID='"+sHurrylogUNID+"'";  
  74.               
  75.             int iReturn = hurry.fnExcuteUpdate(sQuery);  
  76.             if(iReturn==1){  
  77. //              更新hurrylog数据  
  78.                 hurrylogDoc = fnGetDocumentByUNID(hurrylogDb,sHurrylogUNID);  
  79.                 if(hurrylogDoc!=null){  
  80.                     hurrylogDoc.replaceItemValue("v_department", sCurDept);  
  81.                     hurrylogDoc.save(true);  
  82.                 }  
  83.                 curDoc.replaceItemValue("isDone""1");  
  84.                 curDoc.save(true);  
  85.                 pw.println("<script>alert('更新成功!');window.close();</script>");  
  86.             }else{  
  87.                 pw.println("<script>alert('更新失败!');history.back();</script>");  
  88.             }  
  89.           // (Your code goes here)  
  90.   
  91.       } catch(Exception e) {  
  92.           e.printStackTrace();  
  93.        }finally{  
  94.           try{  
  95.               if(pw!=null){  
  96.                   pw.close();  
  97.               }  
  98. //            关闭jdbc相关对象  
  99.               hurry.fnCloseObject();  
  100. //            关闭domino相关对象  
  101.               if (curDoc != null) {  
  102.                   curDoc.recycle();  
  103.               }  
  104.               if(curDb!=null){  
  105.                   curDb.recycle();  
  106.               }  
  107.               if(proDoc!=null){  
  108.                   proDoc.recycle();  
  109.               }  
  110.                             
  111.               if(hurrylogDoc!=null){  
  112.                   hurrylogDoc.recycle();  
  113.               }   
  114.                 
  115.               if(hurrylogDb!=null){  
  116.                   hurrylogDb.recycle();  
  117.               }   
  118.                                         
  119.               if(agentContext!=null){  
  120.                   agentContext.recycle();  
  121.               }  
  122.               if(ss!=null){  
  123.                   ss.recycle();  
  124.               }  
  125.               System.gc();  
  126.           }catch(Exception e){  
  127.               e.printStackTrace();   
  128.           }         
  129.       }  
  130.    }  
  131.     /* 
  132.      * 通过UNID获取数据库文档文档 
  133.      */  
  134.     public Document fnGetDocumentByUNID(Database appDb,String sUNID) throws Exception{  
  135.         Document doc = null;  
  136.         try{  
  137. //          System.out.println("数据库是否存在==" + (appDb!=null));  
  138.             if(appDb!=null && !sUNID.equals("")){  
  139.                 doc = appDb.getDocumentByUNID(sUNID);  
  140. //              System.out.println("文档是否存在==" + (doc!=null));  
  141.             }  
  142.               
  143.         }catch(Exception e){  
  144. //          e.printStackTrace();  
  145.         }  
  146.         return doc;  
  147.     }  
  148. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值