Hi,

I am accessing an executable .jar file from vb.net and I am getting a com.ibm.db2.jcc.am.SQLException Failure in loading native library db2jcct2, no db2jcct2 in java.library.path. But When I am executing same jar directly from my system it is executing fine and is connecting to the database well.

The java code is as follows:

url is built as follows (Note there is no space between ':' and 'port'. It was converting it to a smiley hence I inserted a space here) :
jdbc:db2://server: port/dbalias:user=user;password=password;";
Java code

Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("**** Loaded the JDBC driver");

con = DriverManager.getConnection(url);
// Commit changes manually;
con.setAutoCommit(false);
System.out.println("**** Created a JDBC connection to the data source");

stmt = con.createStatement();
System.out.println("**** Created JDBC Statement object");

rs = stmt.executeQuery("SELECT emp_no FROM tablename FETCH FIRST ROW ONLY");
System.out.println("**** Created JDBC ResultSet object");

while (rs.next()) {
empNo = rs.getString(1);
System.out.println("Employee number = " + empNo);
}

stmt.close();
System.out.println("**** Closed JDBC Statement");

con.commit();
System.out.println ( "**** Transaction committed" );

con.close();

This code is executing perfectly fine when I execute the jar. I have inlcuded db2jcc.jar in the class path and build path.

Code for executing this jar file from vb.net is as follows:

jarfile = "myjar.jar "
jarpath = "C:\Users\myid\mypath\"

Dim processinfo As New ProcessStartInfo()
processinfo.WorkingDirectory = "C:\"
processinfo.FileName = "java.exe"
processinfo.Arguments = "-jar " + jarpath + jarfile
Dim myProcess As New Process()
processinfo.UseShellExecute = False
processinfo.RedirectStandardOutput = True
processinfo.RedirectStandardError = True
myProcess.StartInfo = processinfo
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True

myProcess.Start()
Dim myStreamReader As System.IO.StreamReader = myProcess.StandardOutput
Dim myStreamErr As System.IO.StreamReader = myProcess.StandardError
' Read the standard output of the spawned process.
Dim myString As String
Dim msgout As String = Nothing
Do
myString = myStreamReader.ReadLine()
msgout += myString + vbCrLf
Loop Until (myStreamReader.EndOfStream)
MsgBox(msgout)

Do
myString = myStreamErr.ReadLine()
msgout += myString + vbCrLf
Loop Until (myStreamErr.EndOfStream)
MsgBox(msgout)

myProcess.WaitForExit()
myProcess.Close()

While executing this code it starts looking for native library db2jcct2.

Any help is appreciated!! Many Thanks!!

Peeyush Gera