我正在使用JDBC(Oracle)进行学校作业。 我试图从表中获取一些元组,但resultset.next()每次都得到null值。(从第一次开始) 我使用eclipse和prepareStatement调试,resultSet得到每个值为T4CConnection(id = 82),T4CPreparedStatement(id = 100),OracleResultSetImpl(id = 111)。
Here is the code.
package program;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
public class ProgramDao {
public static Connection getConn(){
Connection conn = null;
try{
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@dblab.sogang.ac.kr:1521:XE";
String user = "DB20111084";
String pwd = "DB20111084";
conn = DriverManager.getConnection(url, user, pwd);
}catch (Exception e1){
e1.printStackTrace();
}
return conn;
}
public Vector<ProgramDto> allTable(){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Vector<ProgramDto> v = new Vector<ProgramDto>();
try{
conn = getConn();
String sql = "SELECT P.PROGRAMNAME, T.TRAINERNAME, P.P_TIME, P.P_CAPACITY FROM PROGRAM P, TRAINER T WHERE P.TID=T.TID";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
ProgramDto dto = null;
**while(rs.next()){
dto = new ProgramDto();
dto.setProgramName(rs.getString(1));
dto.setTrainerName(rs.getString(2));
dto.setP_Time(rs.getString(3));
dto.setP_Capacity(rs.getInt(4));
v.addElement(dto);
}
} catch(Exception e1){
e1.printStackTrace();**
} finally {
try{
if(rs != null){
rs.close();
}
if(pstmt != null){
pstmt.close();
}
if(conn != null){
conn.close();
}
}catch(Exception e2){
e2.printStackTrace();
}
}
return v;
}
...
为什么rs.next每次都变为null并跳转到catch子句。 请帮帮我..