Solved

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

Posted on 2004-09-24
7
3,565 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now