IBM Support

Using Java and the TSM ODBC driver to access the TSM server database

Question & Answer


Question

Is there a JDBC driver for Tivoli Storage Manager (TSM)? If not, is it possible to use Java to access the TSM database?

Answer

TSM does not provide a JDBC driver. Java programmers can use Java's JDBC/ODBC bridge with the TSM ODBC driver to access the TSM server database.

The following code illustrates a simple Java program that diplays the "DATE_TIME" and "MESSAGE" fields from the "ACTLOG" table:

------------------------- BEGIN TSMConnect.java --------------------------
//////////////////////////////////////////////////////////////////////////
// TSMConnect.java: //
//////////////////////////////////////////////////////////////////////////
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");
}

// NOTE - The following arguments must be customized for the
// user's environment:
//
// o Argument 1: Must be of the form "jdbc:odbc:xxxxx" where
// 'xxxxx' is a valid ODBC driver DSN. In this
// example, the DSN is 'amr_odbc'.
// o Argument 2: Must be a valid TSM Administrator ID. In this
// example, the ID is 'raibeck'.
// o Argument 3: Must be the password for the Administrator ID
// specified in argument 2. In this example, the
// password for ID 'raibeck' is 'mypw'.
return DriverManager.getConnection("jdbc:odbc:amr_odbc",
"raibeck",
"mypw");
}

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.");
}
}
}
-------------------------- END TSMConnect.java ---------------------------



---------------------------- BEGIN TSM.java ------------------------------
//////////////////////////////////////////////////////////////////////////
// TSM.java: //
//////////////////////////////////////////////////////////////////////////
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());
}
}
}
----------------------------- END TSM.java -------------------------------





To build the program, run the following command:

javac TSM.java

To execute the program, run the following command:

java TSM



CAUTION - The Java JDBC/ODBC bridge has not been submitted to any formal testing with the TSM ODBC driver. It is the responsibility of the Java programmer to verify the correctness of the results. Users are encouraged to review the README file that accompanies the TSM ODBC driver for further information on supported applications and diagnostics.

NOTE - The recommended version of the TSM ODBC driver is 5.2.2.0 or higher.

NOTE: This article is intended to provide a simple example of how Java programs can access the TSM server database via the Java JDBC/ODBC bridge and the TSM ODBC driver. It is not the intention of this article to provide a full treatment of Java or JDBC/ODBC bridge programming in general. Users with additional questions on Java or JDBC/ODBC bridge programming should refer to the formal Java and JDBC documentation or other publications that cover these topics in more detail.

[{"Product":{"code":"SSGSG7","label":"Tivoli Storage Manager"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Client","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Supported Versions","Edition":"","Line of Business":{"code":"LOB26","label":"Storage"}}]

Document Information

More support for:
Tivoli Storage Manager

Software version:
All Supported Versions

Document number:
662235

Modified date:
17 June 2018

UID

swg21080948