witlili witlili - 2 months ago 8
Java Question

NotesException:Older version on server does not support this method

Lotusscript calling Java class get this error.
abstract:
Product Area: Domino Designer on Eclipse (DDE)

Technical Area: Application Development

Platform: Windows 2008 R2 64bit

Release: 8.5.3

Reproducible: Always

1 create SqlTest script libray(Java) in Notes database.
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 in the Notes form:

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 use the java class through Lotusscript:

'call java class

Call jTest(doc.UniversalID)


4 debug the program find the error in java console log through IDE(Lotus Domino Designer).use some print sentences and find the error line(Java):

Database db = s.getCurrentDatabase();


5 I have had seen follow posts.

Invoking method on a Java class from lotus script (LS2J)

passing LotusScript parameter to Java

google Nothing,trouble for days.
thanks everyone,thanks in advance.First Posts in stackoverflow.

Answer

The problem is in the way you get your session: you open a complete new one that has nothing to do with the currently open session. That new session does not have a current database as it is not connected to you frontend session.

Just initialize your session with this line:

Session session = getSession();

Then getCurrentDatabase will work.