XPages Example: Calling Java Methods directly from server side JavaScript - performing an SQL query Part 207/07/2008| package javaMethods;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class SQLQuery{ public static String executeQuery(String connDB, String connUserName, String connPwd, String query){ String theResult=""; ResultSet resultSet=null; try { // load the DB2 Driver Class.forName("com.ibm.db2.jcc.DB2Driver"); // establish a connection to DB2 Connection db2Conn = DriverManager.getConnection(connDB,connUserName,connPwd); Statement st = db2Conn.createStatement(); // execute the query resultSet = st.executeQuery(query); while (resultSet.next()) { //theResult will be the 1st column separated using ";" theResult=theResult+resultSet.getString(1)+";"; } } catch(Exception e){ System.out.println(e); } return theResult; } } |
| var connString="jdbc:db2://localhost:50000/sample";
var userName="db2admin"; var pwd="password"; function getDeptNumbers(){ var query="SELECT DEPTNO FROM ADMINISTRATOR.DEPARTMENT"; depts=javaMethods.SQLQuery.executeQuery(connString,userName,pwd,query); return @Explode(depts,";"); } function getDepartment(deptNo){ print("dept="+deptNo); var query="SELECT DEPTNAME FROM ADMINISTRATOR.DEPARTMENT WHERE DEPTNO='"+deptNo+"'"; dept=javaMethods.SQLQuery.executeQuery(connString,userName,pwd,query); return dept; } |
1. chengqi11/01/2008 02:53:41 AM
This is a question not about Javascript to call Java, it is about something else. But I didn't find a post that is correlated, so I just posted my question here.
You know, after I switched to Java Perspective, I found that all the form/view elements are shown as XMLs, then does it mean that I can edit them manually(if I know how surely). This will also lead to some changes to Version Control System of DDE8.5 development system. Previously, we've to use something like TeamStudio/CIAO, so now we can use Subversion/ClearCase, is that correct? We can also even able to do form/view elements merge sometimes. If this is true, it is really great news.
Thanks.
2. chengqi11/01/2008 03:08:39 AM
This comment is not about JavaScript calling Java, but I didn't find a relevant post in the site, so I just posted it here.
After switching perspective from Domino Designer to Java, I found that all the form/view elements are just XMLs now, this is also a new change of Domino 8.5, correct? Does it mean that I can manually modify it if I know how to? Besides, if that's true, then we might be able to drop TeamStudio/CIAO version control system for NSF development, and adopt Subversion or ClearQuest, where we even can implement code merges, this will be another good news....
Thanks.
Cheng Qi
3. wgb.sky05/25/2009 03:03:23 AM
John,
can you tell me how to running java in the
java view?
4. Jerry Shelley06/18/2009 11:12:24 AM
I'm trying to get a JDBC DataDirect SQLServer connection working, but failing with ClassNotFoundException on "com.ddtek.jdbc.sqlserver.SQLServerDriver". Not the Lotus provided ones, as I can't find them, but a downloaded set from the JDBC DataDirect site.
I've added the sqlserver.jar file from the JDBC installation into the Domino\java\xsp\shared\lib (although you mention Domino\xsp\shared\lib so I've created that as well) to no effect.
I've also added the jar into the NSF Project using Project Properties, also with no joy.
Any thoughts on how to remedy would be gratefully received.
Thanks and Regards.
Jerry.
5. Sravan Kumar07/25/2009 10:47:02 PM
John, I get a error java.lang.classnotfoundexception:net.sourceforge.jtds.jdbc.Driver on the server when I try this example to connect MSSQL server.which Driver is supporting to MSSQL
thanks,
6. Laura S10/26/2009 11:37:33 AM
John,
This looks really cool and I think I am ALMOST there. Using 8.5.1... it will not allow me to create the javaMethods package under the source (normal folder) I create. It forces it under Local. If I try to make my "source" folder by right clicking and select New->"Source Folder"... it again forces my selection to the local folder only. Is there a feature change here? Or am I doing something wrong?
Thanks for any help!!
Laura
7. Scott Blaylock11/29/2009 08:35:26 AM
I'm using 8.5.1 and have found a way to get this working without having to add the database jar files to the Domino server. From the java perspective, create a 'lib' folder under 'WebContent\WEB-INF' (if it doesn't already exist). Right-click over the 'lib' folder and select Import. Twist open or double-click General, doulble-click 'File System'. Browse to the directory where your database .jar files are. In the right column select your database .jar(s). In my case I'm using MySQL on an iSeries (AS400), so the file I imported was mysql-connector-java-5.1.10-bin.jar. JAR files placed in this directory are stored in your NSF and automatically appended to the run time class path of JavaScript.
Scott.
8. Karthick04/16/2010 06:19:04 AM
Homepage: http://ozinisle.blogspot.com
Hi John,
This is very helpful. I followed all the steps and eventually things work fine for me.
When I attempted it the second time, I started facing the issue that was mentioned by Laura - the javaMethods package under the source which I create is forced under Local.
Proceeding further, creating the package and the java file under local, and dragging and dropping the same under the source folder works .
But is there any fix to this?... Am I missing some thing?
thanks,
Karthick
9. Atul Saxena04/26/2010 09:48:34 AM
Dear John,
Thanks for posting. It works beautifully with db2 on AS/400 and good tip by Scott Blaylock. This kind of posting will be very helpful in making Lotus Notes/Domino Successful.
Best Regards
Atul Saxena
10. Vladimir10/18/2010 02:38:38 AM
Hi all!
Have a problem with db2 jar files on Domino 8.5.2. Not working, generating an error "ClassNotFoundException".
Anybody knows where jar files are to be with Domino 8.5.2?
This problem on 8.5 Forum:
{ Link }
11. Ravikiran Kodali11/15/2010 01:19:35 PM
Thank you for detailed Article.
I got this working for oracle by making the following changes. Hope this would be usefull for others.
In the script library, changed the connection parameters.
Var connString="jdbc:oracle:thin:@localhost:1521:dbname";
Copied ojdbc14.jar from the oracle install folder(c:/oracle/ora10g/JDBC/lib) folder to domino/xsp/shared/lib folder and restarted http.
In the SQLquery.java changed the driver to Class.forName("oracle.jdbc.driver.OracleDriver");
12. Priya01/05/2011 12:29:21 PM
Homepage: http://www.fromdev.com/
Thanks, it was a well explained post.
13. Santosh03/27/2011 10:55:30 PM
I have followed, the Sample example of Xpages connectivity with DB2. But when I am executing Employee Xpage It gives below mentioned error on Domono Console
HTTP JVM: com.ibm.db2.jcc.am.BugCheckException: Origination unknown: [1026][13304][3.57.82] Bug check exception thrown due to an internal JCC error. Please contact support. Message text: {0} ERRORCODE=-4228, SQLSTATE=null
I have copied db2jcc.jar & db2jcc_license_cu.jar files on domino server & I am using DB2 V9.7.0.441 version. Can u help me out to resolve this error.
Thanks in Advance
14. Naseer07/08/2011 11:28:24 PM
Hi Atul,
I did all the steps said by John in this video, buy when I try to connect to DB2 server which is on AS400, It gives me below error
Error 403
HTTP Web Server: You are forbidden to perform this operation "
Can you please post what are the additional steps required to connect to DB2 server on AS400 server. I am using the same driver as said by John "db2jcc.jar", is this the correct driver to connect to DB2 on AS400 machine.
Regards,
Naseer
15. Michael07/14/2011 01:30:23 AM
Hi,
how can I store java packages in a template? Every time, I use a template with java classes in a package, it is gone or moved to an simple folder structure, not reachable by the application.
MV
16. Michael07/14/2011 01:32:19 AM
Hi,<br><br>how can I store java packages in a template? Every time, I use a template with java classes in a package, it is gone or moved to an simple folder structure, not reachable by the application.<br><br>MV
17. Tom08/10/2011 11:08:01 AM
@11 - Thank you, Ravikiran!!
18. slimane10/18/2011 08:28:00 AM
This works fine when there is only one column and fews rows.
But what about few columns and few rows?
Is it possible to get an object from java to javascript ?
tks