package com.niit.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;import com.niit.entity.Student;
import com.niit.iface.IStuDao;public class StudentDao extends BaseDao implements IStuDao
{
private Connection con;
private ResultSet rs;
private PreparedStatement pstmt; public ArrayList<Student> findAllStudent()
{
ArrayList<Student> stuList=new ArrayList<Student>();

con=getConnection(); if(con!=null)
{
try
{
pstmt=con.prepareStatement("select * from student");

rs=pstmt.executeQuery();
//此处为false,但是上面的sql语句在oracle中能查到,为啥这里查不到呢
System.out.println(rs.next()); while(rs.next())
{
Student stu=new Student();

stu.setStuName(rs.getString(1));
stu.setStuId(rs.getInt(2));
stu.setBirthday(rs.getTimestamp(3));
stu.setSex(rs.getString(4));
stu.setEmail(rs.getString(5));

stuList.add(stu);
}

} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
closeAll(rs, pstmt, con);
}
}

return stuList;
}

}
oracle数据库

解决方案 »

  1.   

    Class.forname(driveClassName);
    con=DriverManager.getConnection(url,username,password);
    数据库没连上吧!
    这样试试看看然后在写SQL语句
    pstmt=con.prepareStatement("select * from student");                   
      

  2.   

    connection我已经通过父类的方法获取到了,如果没获取到connection跟本不会进入这个条件结构 if(con!=null),还是谢谢你,不过你的那些代码我都实现了的