×

Loading...

a jdbc problem

本文发表在 rolia.net 枫下论坛I write a jdbc program to connect to a db2 database's table, table is created by:
create table mytest(name varchar(20),age int).
The following is my program:
import java.sql.*;
import java.io.*;
class my{
public static void main(String args[]){
String dsn="jdbc:db2:mydb";
String userid="mydb2user";
String pwd="myuser";
Connection conn=null;
Statement stmt=null;
ResultSet rSet=null;
try{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
}
catch(Exception e){
e.printStackTrace();
}
try{
conn=DriverManager.getConnection(dsn,userid,pwd);
stmt=conn.createStatement();
rSet=stmt.executeQuery("select * from mytest");
System.out.println("the column of datetype");
while(rSet.next())
{
int i=0;
String nm=rSet.getString(1);
int ag=rSet.getInt(2);
System.out.println("The name is: "+nm);
System.out.println("The age is: "+ag);
System.out.println(">>>>>>>> "+i );
i++;

}
rSet.close();
stmt.close();
conn.close();

}
catch(SQLException e){e.printStackTrace();}

}
}

I can't get correct result,only get a loop:
The age is: 0
>>>>>>> 0
The name is:
>>>>>>> 0
The age is: 0
The name is:
>>>>>>> 0
........
It looked like the while() never continued.

my machine is winnt+jdk1.2+db25.0
I changed the driver to ODBC,but get the
same result, who can tell me what's wrong
in my program?更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions: