Hi,
I want to connect to DB2 in remote machie through RFT in my local machine.
I have used the below code,
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import COM.ibm.db2.jdbc.app.DB2Driver;
public class DB2Connection {
/**
* Script Name : <b> DB2Connection</b>
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @author Admin
*/
public Connection connection = null;
public ResultSet resultset = null;
public Statement statement = null;
public void connect() throws Exception
{
Driver driver = new COM.ibm.db2.jdbc.app.DB2Driver();
DriverManager.registerDriver(driver);
System.out.println("Driver Loaded Successfully ...");
connection = DriverManager.getConnection("jdbc:db2:<database name here>","<Usernamehere>", "<pwd here>");
System.out.println("Driver Loaded Next ...");
if (connection == null)
{
System.out.println("connection failed");
}
connection.setAutoCommit(true);
System.out.println("Successfully Connected to DB2...");
statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery("<query here>");
System.out.println(rs.first());
//System.out.println(rs.getArray(1));
for (int i=1;i<15;i++) {
System.out.println(rs.getObject(i));
}
//System.out.println(rs.getArray("Address_line_one"));
System.out.println("Hi");
//statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
}
public ResultSet query(
String arg) throws SQLException
{
try
{
statement = connection.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
//resultset = statement.executeQuery( Select * from <WCC>);
}catch (Exception ioe)
{
System.out.println("Query failed: " + arg);
ioe.printStackTrace();
}
return resultset;
}
public void close () throws Exception
{
if (connection != null)
{
try
{
connection.commit();
connection.close();
}catch (Exception e)
{
System.out.println("Problem in closing DB2 connection: " + e.getMessage());
}
connection = null;
}
}
public static void main(String args[])
{
DB2Connection db = new DB2Connection();
try {
db.connect();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and I've included db2jcc and db2 licence jar files in the java -classpath
Still I am not able to connect to the database, I am geting the below error
"java.SQL.SQLException: java.lang.UnsatisfiedLinkError: db2jdbc (Not found in java.library.path)
at COM.ibm.db2.kdbc.app.DB2Driver.<init>(Unknown source)"
Can someone please help me on this.....
PraveeN