mport java.sql.*;
import java.util.ArrayList;
import java.util.List;
import com.etc.dao.GetConnectionFactory;
import com.etc.model.Customer;
public class CustomerDAOImpl
{
public List<Customer> selectbybirth(Date stime,Date etime )
{
List<Customer> list = new ArrayList<Customer>();
Connection conn = GetConnectionFactory.getconnection();
String sql = "select * from customer where cbirth between '?' and '?'";
Customer cm = null;
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setDate(1, stime);
pstmt.setDate(2, etime);
ResultSet rs1 = pstmt.executeQuery(sql);
while (rs1.next()) {
cm = new Customer(rs1.getString(1), rs1.getInt(2),
rs1.getString(3), rs1.getDate(4));
list.add(cm);
}
pstmt.executeQuery();
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return null;
}
pstmt.setDate(2, etime);这个数值就没跳出来,
pstmt.setDate(1, stime);直接跳到了SQLException 的异常。求大侠帮忙看看哪里错了
------解决方案--------------------
- SQL code
String sql = "select * from customer where cbirth between ? and ?";
------解决方案--------------------