ADSM-L

Re: JDBC-ODBC Bridge and TSM ODBC driver

2002-05-10 15:39:35
Subject: Re: JDBC-ODBC Bridge and TSM ODBC driver
From: Andrew Raibeck <storman AT US.IBM DOT COM>
Date: Fri, 10 May 2002 15:39:52 -0400
You need to use the JDBC <--> ODBC bridge. There is no JDBC driver for
TSM, nor do we plan on implementing one at this time.

Which version of the ODBC driver are you using? The only ones that I know
of that work (to at least some minimal degree) are 5.1.0.1 and now
4.2.2.0. Any future versions should also work. Note that we do not perform
extensive testing with the bridge, so we do not formally support it, and I
can not guarantee results. However, I can at least issue a select
statement and get results back.

I haven't worked with Java in at least 2 years (and am extremely rusty),
and I have almost zero experience with the JDBC-ODBC bridge. However, I
did pick up a book by Gregory D. Speegle called "JDBC Practical Guide for
Java Programmers" which gives information on how to do this.

Adapting an example from that book, I came up with some code that displays
the DATE_TIME and MESSAGE field from the ACTLOG table:

TSMConnect.java:
============================================================
import java.sql.*;
import java.sql.*;

public class TSMConnect
{
    public Connection connect()
           throws SQLException
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch (ClassNotFoundException e)
        {
            throw new SQLException("Unable to load JdbcOdbcDriver class");
        }

        // arguments are "jdbc:odbc:yourdsn", "youradmin", "yourpw"
        return DriverManager.getConnection("jdbc:odbc:amr_odbc",
                                           "raibeck",
                                           "tsm0dbc");
    }

    public void close(Connection dbc, Statement stmt)
    {
        try
        {
            if (stmt != null)
                stmt.close();
            if (dbc != null)
                dbc.close();
        }
        catch (SQLException sqlex) {}
    }

    public static void main(String args[])
    {
        TSMConnect TC = new TSMConnect();
        Connection dbc = null;
        Statement stmt = null;
        try
        {
            dbc = TC.connect();
            System.out.println("Connection opened.");
            stmt = dbc.createStatement();
            System.out.println("Created a statement.");
        }
        catch (SQLException sqlex)
        {
            System.out.println(sqlex.getMessage());
        }
        finally
        {
            TC.close(dbc, stmt);
            System.out.println("Connection closed.");
        }
    }
}
============================================================
TSM.java:
TSM.java:
============================================================
import java.sql.*;
import java.sql.*;

public class TSM extends TSMConnect
{
    public static void main(String args[])
    {
        if (args.length != 0)
        {
            System.out.println("Usage: java TSM");
            System.exit(1);
        }

        String query = "SELECT * FROM ACTLOG";

        TSM tsmObj = new TSM();
        Connection dbc = null;
        Statement stmt = null;
        ResultSet resultSet = null;

        try
        {
            dbc = tsmObj.connect();
            stmt = dbc.createStatement();
            resultSet = stmt.executeQuery(query);
            tsmObj.presentResultSet(resultSet);
        }
        catch (SQLException sqlex)
        {
            System.out.println(sqlex.getMessage());
        }
        finally
        {
            tsmObj.close(dbc, stmt);
        }
    }

    public void presentResultSet(ResultSet rs)
           throws SQLException
    {
        if (!rs.next())
            System.out.println("No records to display");
        else
        {
            do
            {
                System.out.println(rs.getString("DATE_TIME") + ": " +
rs.getString("MESSAGE"));
            }
            while (rs.next());
        }
    }
}
============================================================
Note that you need to put your DSN, admin ID, and admin password in the
Note that you need to put your DSN, admin ID, and admin password in the
TSMConnect.java file.

To build the code, run

   javac TSM.java

To run the code

   java TSM

Regards,

Andy

Andy Raibeck
IBM Software Group
Tivoli Storage Manager Client Development
Internal Notes e-mail: Andrew Raibeck/Tucson/IBM@IBMUS
Internet e-mail: storman AT us.eyebm DOT com (change eye to i to reply)

The only dumb question is the one that goes unasked.
The command line is your friend.
"Good enough" is the enemy of excellence.

Forum:   ADSM.ORG - ADSM / TSM Mailing List Archive
 Date:      May 10, 06:20
 From:      Warren, Matthew James <matthewjames.warren AT EDS DOT COM>

He TSM'ers,

Has anyone any success connecting to the TSM database using the JDBC-ODBC
bridge and the TSM ODBC drivers? I have set bot system and user
datasources
using the TSM ODBC driver, and I am then attmepting to access this from
Java
using the JDBC-ODBC bridge.

Currently I am using this code in a Main method;

try
{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException CNFE)
{
    System.out.println(CNFE.toString());
}
try
{
    Connection con =
DriverManager.getConnection("jdbc:odbc:SPADUX","{auserid}","{apassword}");
}
catch(SQLException SQLE)
{
    System.out.println(SQLE.toString());
}


I have tried with both a System DSN setup called SPADUX using the TSM ODBC
drivers, and a user DSN.


And I get the following error;

Session established with server SPADUX0001: Solaris 7/8
  Server Version 4, Release 2, Level 1.9
  Server date/time: 05/10/2002 11:12:44  Last access: 05/10/2002 11:05:26

java.sql.SQLException: General error
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6138)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6266)
        at sun.jdbc.odbc.JdbcOdbc.SQLColAttributes(JdbcOdbc.java:2044)
        at
sun.jdbc.odbc.JdbcOdbcResultSet.getColAttribute(JdbcOdbcResultSet.java:5241)
        at
sun.jdbc.odbc.JdbcOdbcResultSet.getColumnType(JdbcOdbcResultSet.java:5870)
        at
sun.jdbc.odbc.JdbcOdbcResultSet.getMaxCharLen(JdbcOdbcResultSet.java:5269)
        at
sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:267)
        at
sun.jdbc.odbc.JdbcOdbcConnection.buildTypeInfo(JdbcOdbcConnection.java:1473)
        at
sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:379)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
        at java.sql.DriverManager.getConnection(DriverManager.java:515)
        at java.sql.DriverManager.getConnection(DriverManager.java:174)
        at TSMBillMan.main(TSMBillMan.java:32)


If I use the Forte4J CE Database connection class wizard, I get the extra
information along with the above;

'Unable to Connect: TSM: There is no information about this table'

When the wizard attempts to connect to the DB. I guess the wizard is
attempting to query something similar to the syscat tables to discover
details about the database??


Has anyone else come across this, or succesfully used the JDBC-ODBC Bridge
and the TSM ODBC driver?
<Prev in Thread] Current Thread [Next in Thread>