Solved

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

Posted on 2004-09-24
7
3,548 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

17 Experts available now in Live!

Get 1:1 Help Now