Solved

Connecting to ODBC Source (SQL db) from a Domino Java agent

Posted on 2004-09-24
7
3,594 Views
Last Modified: 2013-12-18
I've got a System DSN ODBC connection on the server which is working fine for scheduled LotusScript agents to connect to a SQL server on our network.

Problem: I'm trying to connect to this same SQL server through a Java agent -- I can't seem to get the JDBC driver right.

Here's the text of my simple ODBC test agent.  The system DSN name is "SLXSystem".  As you can probably tell, this is my first time accessing an ODBC data source from a Java agent.  Please help!

I'm running Domino 6.5.1.

import lotus.domino.*;
import java.sql.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

            try {
                  Session session = getSession();
                  AgentContext agentContext = session.getAgentContext();
                  System.out.println(session.getUserName());
                  
                  Class.forName("sun.jdbc.odbc.JdbcDriver");
//I'M NOT SURE WHAT SHOULD BE IN THE ABOVE LINE
                  Connection conn = DriverManager.getConnection("jdbc:odbc:SLXSystem", "sysdba", "masterkey");
                  Statement st = conn.createStatement();
                  ResultSet rec = st.executeQuery("select firstname from sysdba.contact where lastname = 'crompton'");
                  while (rec.next()){
                        System.out.println(rec.getString(1));                        
                  }
                  st.close();                  
            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}

**********
These are the errors I get in the Notes Log:
09/24/2004 02:20:53 PM  Agent  error: java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcDriver
09/24/2004 02:20:53 PM  Agent  error:       at lotus.domino.AgentLoader.loadClass(Unknown Source)
09/24/2004 02:20:53 PM  Agent  error:       at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
09/24/2004 02:20:53 PM  Agent  error:       at java.lang.Class.forName1(Native Method)
09/24/2004 02:20:53 PM  Agent  error:       at java.lang.Class.forName(Class.java:142)
09/24/2004 02:20:53 PM  Agent  error:       at JavaAgent.NotesMain(JavaAgent.java:20)
09/24/2004 02:20:53 PM  Agent  error:       at lotus.domino.AgentBase.runNotes(Unknown Source)
09/24/2004 02:20:53 PM  Agent  error:       at lotus.domino.NotesThread.run(NotesThread.java:215)
0
Comment
Question by:chriscromp
  • 4
  • 2
7 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12146924
>  sun.jdbc.odbc.JdbcDriver
basically it needs the jdbc driver installed on the server..

or use jdbc-odbc bridge and configure odbc driver and deal with that

~Hemanth
0
 

Author Comment

by:chriscromp
ID: 12146965
Actually, Through some further troubleshooting, I found that the line

Class.forName("sun.jdbc.odbc.JdbcDriver");

had a miss-type -- it should have been

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

IT WORKS NOW!!
0
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 400 total points
ID: 12147570
That is basically you are using jdbc-odbc bridge. And you don't have jdbc driver !!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:chriscromp
ID: 12147649
Class.forName("sun.jdbc.odbc.JdbcDriver");

So the above line would actually work if I had a jdbc driver?  
Are there any advantages to using this driver over the jdbc-odbc bridge?
Would I still be using one of my ODBC connections if I were using the jdbc driver itself?

Thanks for the info!
0
 
LVL 15

Assisted Solution

by:Bozzie4
Bozzie4 earned 100 total points
ID: 12147808
Don't use odbc if you use jdbc.  Use the native jdbc driver (for sql server) instead for better results ....

cheers,

Tom
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12148244
The correct syntax for the case of db2 would be like this

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");  // THis would be the jdbc driver provided by db2 !!!
conn = DriverManager.getConnection( "jdbc:db2:DataBaseName", "User", "Password");

0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12148245
For SQL check the support site or downloads for jdbc drivers
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question