Lotusscript调用Java类得到此错误。文摘:产品领域:Domino Designer on Eclipse (DDE)
技术领域:应用开发
平台:Windows 2008 R2 64bit
发布: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在Notes表单中:
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();
我已经看到了后续的帖子。
从lotus脚本(LS2J)调用Java类上的方法
将LotusScript参数传递给Java
没有,麻烦了好几天。谢谢大家,提前感谢。问题在于您获取会话的方式:您打开了一个与当前打开的会话无关的全新会话。这个新会话没有当前数据库,因为它没有连接到你的前端会话。
用这行初始化你的会话:
Session session = getSession();
感谢Torsten Link。我测试了很多次java脚本库,都失败了。新的Javaagent不是java脚本库,然后一切都清楚了。
core 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
core javaagent code:
Agent agent = agentContext.getCUrrentAgent()
Document doc = db.getDocumentbyID(agent.getParameterDocID())
注意:运行时安全级别,您需要允许限制操作