Solved

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

Posted on 2004-09-24
7
3,612 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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