Lotusscript调用Java类会出现此错误。 抽象: 产品领域:Eclipse上的Domino Designer(DDE)
技术领域:应用程序开发
平台:Windows 2008 R2 64位
发布:8.5.3
可重复:始终
1在Notes数据库中创建SqlTest脚本库(Java)。 Model.java:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import lotus.domino.*;
public class Model{
/**
Get database connection
@return
*/
public static Connection getConn(){
Connection conn = null;
String SqlDriverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String SqlDBUrl = "jdbc:sqlserver://22.11.95.30:1433;DatabaseName=TMSTEST";
String SqlUserName = "sa";
String Sqlpwd = "1q2w3e4r!";
try {
Class.forName(SqlDriverName);
conn = DriverManager.getConnection(SqlDBUrl, SqlUserName, Sqlpwd);
System.out.println("database connection sucess");
} catch (Exception e) {
e.printStackTrace();
System.out.println("database connection failure");
}
return conn;
}
public static boolean test1(String id){
//System.out.println("---------------------");
Connection conn = getConn();
Statement stmt = null;
String sql;
// Open the current Notes db
try {
Session s = NotesFactory.createSession("22.11.95.100:63148", "admin test/testeam", "testtest");
System.out.println("session is OK");
Database db = s.getCurrentDatabase();
// System.out.println("Title of URL database: \"" + db.getTitle() + "\"");
if (db.isOpen())
System.out.println("Is open");
else
System.out.println("Not open");
Document doc = null;
//through the id para get the Notesdocument
doc = db.getDocumentByUNID(id);
System.out.println(id);
//insert the Notesdocument data to sql
if (doc != null) {
sql = "insert into TEST_USER(userID, userName,xqbh) values('123456','"+doc.getItemValueString("fld_xqbh")+"', '"+doc.getItemValueString("fld_xqmc")+"')";
System.out.println("SQL :"+sql);
stmt = conn.createStatement();
stmt.execute(sql);
System.out.println("excute finish");
return true;
}else{
return false;
}
} catch (NotesException e) {
// TODO auto generate catch block
e.printStackTrace();
return false;
}catch(SQLException se){
se.printStackTrace();
return false;
}finally{
try{
if(stmt != null) stmt.close();
if(conn != null) conn.close();
}catch(Exception e1){
e1.printStackTrace();
}
}
}
}
备注表格中的2:
Uselsx "*javacon"
Use "SqlTest"
Function jTest(id As String) As Boolean
Dim jSession As New JAVASESSION
Dim jClass As JAVACLASS
Dim jObj As JavaObject
Set jClass = jSession.GetClass("Model")
'Msgbox jClass.className
Call jClass.test1(id)
End Function
3通过Lotusscript使用java类:
'call java class
Call jTest(doc.UniversalID)
4调试程序通过IDE(Lotus Domino Designer)在java控制台日志中找到错误。使用一些打印句子并找到错误行(Java):
Database db = s.getCurrentDatabase();
5我见过以下帖子。
谷歌什么都没有,麻烦好几天了。 谢谢大家,先谢谢。stackoverflow中的第一篇文章。答案 0 :(得分:1)
问题在于您获得会话的方式:您打开一个与当前打开的会话无关的全新会话。该新会话没有当前数据库,因为它没有连接到您的前端会话。
只需使用以下行初始化您的会话:
Session session = getSession();
然后getCurrentDatabase将起作用。
答案 1 :(得分:0)
核心LotusScript代码:
Dim agent As NotesAgent
Set db = s.CurrentDatabase
Set agent = db.GetAgent("javaAgent")
If agent.RunOnServer(doc.NotesID) = 0 Then
Messagebox "Agent ran",, "Success"
Else
Messagebox "Agent did not run",, "Failure"
End If
核心javaagent代码:
Agent agent = agentContext.getCUrrentAgent()
Document doc = db.getDocumentbyID(agent.getParameterDocID())
注意:运行时安全级别,您需要允许限制操作。