Hi, I have the file db2jcc.jar sitting in my home directory, and have installed java 1.3.1 on my system. How can I use this db2jcc file to get data from a remote db2 server? Can you please post sample code (I was able to do it with a java applet, but I want my program to output the result to a text file). The code I wrote:
import java.sql.*;
import java.awt.*;
public class test {
public static void main(String args[]) {
int i = 0;
Connection con = null;
System.out.println("Connecting..."
try {
String url = "jdbc:db2://hostort/db_name";
Class.forName("COM.ibm.db2.jcc.DB2Driver".newInstance();
con = DriverManager.getConnection(url, "usr", "pswd"
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tbl"
System.out.println("Retrieving data"
while (rs.next() && (i < 15)) {
System.out.println(i+":"+rs.getString(1));
i ++;
}
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
$echo $CLASSPATH outputs /home/mydir/db2jcc.jar
$javac test.java -> runs fine
$java test -> java.lang.NoClassDefFoundError: test
What did I do wrong?
import java.sql.*;
import java.awt.*;
public class test {
public static void main(String args[]) {
int i = 0;
Connection con = null;
System.out.println("Connecting..."
try {
String url = "jdbc:db2://hostort/db_name";
Class.forName("COM.ibm.db2.jcc.DB2Driver".newInstance();
con = DriverManager.getConnection(url, "usr", "pswd"
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tbl"
System.out.println("Retrieving data"
while (rs.next() && (i < 15)) {
System.out.println(i+":"+rs.getString(1));
i ++;
}
stmt.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
$echo $CLASSPATH outputs /home/mydir/db2jcc.jar
$javac test.java -> runs fine
$java test -> java.lang.NoClassDefFoundError: test
What did I do wrong?