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数据库
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数据库
con=DriverManager.getConnection(url,username,password);
数据库没连上吧!
这样试试看看然后在写SQL语句
pstmt=con.prepareStatement("select * from student");