Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3741
  • Last Modified:

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

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
chriscromp
Asked:
chriscromp
  • 4
  • 2
2 Solutions
 
HemanthaKumarCommented:
>  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
 
chriscrompAuthor Commented:
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
 
HemanthaKumarCommented:
That is basically you are using jdbc-odbc bridge. And you don't have jdbc driver !!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
chriscrompAuthor Commented:
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
 
Bozzie4Commented:
Don't use odbc if you use jdbc.  Use the native jdbc driver (for sql server) instead for better results ....

cheers,

Tom
0
 
HemanthaKumarCommented:
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
 
HemanthaKumarCommented:
For SQL check the support site or downloads for jdbc drivers
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now