a jdbc problem

netman (NetMan)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
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/zh
(#12763@0)
2000-11-1 -05:00

回到话题: a jdbc problem

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=12763