Edito la pregunta. Estoy creando una Jtable que se alimenta de una BD Sql server. El procedimiento para la consulta es este:
private static final String SELECT_FILTRO_FECHAS="SELECT REPOSTAJES.ID, FLOTA.MATRICULA,REPOSTAJES.NUM_FLOTA,REPOSTAJES.FECHA,REPOSTAJES.KMTS,"+
"REPOSTAJES.LITROS, REPOSTAJES.LIT_ADBLUE,VEHICULOS.EMPRESA,REPOSTAJES.COM_ACUM,REPOSTAJES.ADB_ACUM\n" +
"FROM REPOSTAJES INNER JOIN FLOTA\n" +
"ON REPOSTAJES.NUM_FLOTA=FLOTA.NUM_FLOTA\n" +
"INNER JOIN VEHICULOS\n" +
"ON VEHICULOS.NUM_FLOTA=FLOTA.NUM_FLOTA WHERE REPOSTAJES.NUM_FLOTA=?"+
"AND REPOSTAJES.FECHA>=? AND REPOSTAJES.FECHA <=?"+
"ORDER BY REPOSTAJES.KMTS DESC";
public static HashMap<Integer,RepostajeDTO> selectRepostajeFiltradoFechas( int num, Calendar fecha1, Calendar fecha2)throws Exception{
HashMap<Integer,RepostajeDTO> mapa=new HashMap<>();
ResultSet rs=null;
PreparedStatement st=null;
Datasource data=null;
try{
data=new Datasource();
st=data.getStatement(SELECT_FILTRO_FECHAS,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.setInt(1, num);
java.util.Date fecha=fecha1.getTime();
java.sql.Date fsql= new java.sql.Date(fecha.getTime());
st.setDate(2, fsql);
java.util.Date fech=fecha2.getTime();
java.sql.Date fsql2= new java.sql.Date(fech.getTime());
st.setDate(3, fsql2);
rs=data.ejecutarSelect(st);
while(rs.next()){
RepostajeDTO m=new RepostajeDTO();
m.setId(rs.getInt("ID"));
m.setMatricula(rs.getString("MATRICULA"));
m.setNum_flota(rs.getInt("NUM_FLOTA"));
//FECHA
SimpleDateFormat dateformater=new SimpleDateFormat("dd/MM/yyyy");
Date f=rs.getDate("FECHA");
Calendar fechaoP= Calendar.getInstance();
fechaoP.setTime(f);
m.setFecha(fechaoP);
//Hasta aqui la fecha
m.setKmts(rs.getInt("KMTS"));
m.setLitros(rs.getFloat("LITROS"));
m.setLit_adblue(rs.getFloat("LIT_ADBLUE"));
m.setEmpresa(rs.getString("EMPRESA"));
m.setCom_acum(rs.getFloat("COM_ACUM"));
m.setAdb_acum(rs.getFloat("ADB_ACUM"));
//añadido al Mapa. El ID será la clave para el objeto añadido.
mapa.put(rs.getInt(1), m);
}
//Cerrar el ResultSet
rs.close();
return mapa;
}catch(Exception ex){
throw ex;
}finally{
if(st!=null){
//Cerrar la consulta parametrizada
st.close();
//Cerrar la conexion.
data.cerrarConexion();
}
}
}
Los parametros pasados son: Dos fechas que vienen de un JDateChooser (En el código las paso a formato SQL para que la BD de SQL server las entienda) Un int que viene de una matriz de Integers.
Al ejecutarse el programa, se cargan correctamente los valores de las fechas y del int pero al llegar a rs=data.ejecutarSelect(st); salta un error que dice: "Debe declarar la variable escalar @POAND"
fech.getTime()
?