Jump to content

JAVA & MYSQL throught JDBC - List<VO> error

So, I'm having big problems getting my mysql query to get through.

I'm getting some data from my mysql db to fill a JTable, everything was working fine until I decided that I need a 'WHERE' clause in my sql statement.

 

This is the code, I can't seem to figure out how to insert the WHERE data from the method:

public List<VOSesion> listarSesion(int dia, int mes){	Connection con = null;	con = this.conectarBD();	VOSesion sesion = null;	List<VOSesion> lstSesion = null;	PreparedStatement pstmt;	try{		Consultas consultas = new Consultas();		pstmt = con.prepareStatement(consultas.listarSesion());		pstmt.setInt(1, dia);		pstmt.setInt(2, mes);		ResultSet rs = pstmt.executeQuery();		lstSesion = new ArrayList<VOSesion>();		while(rs.next()){			sesion = new VOSesion(rs.getInt("id"), rs.getInt("id_cli"), rs.getInt("id_trat"), rs.getInt("hora"), rs.getInt("dia"), rs.getInt("mes"));			lstSesion.add(sesion);		}		rs.close();		pstmt.close();	}catch(SQLException e){		e.printStackTrace();	}	this.desconectarBD(con);	return lstSesion;	}

where "consultas.listarSesion()" is:

public String listarSesion(){	String consulta = "SELECT id, id_cli, id_trat, hora, dia, mes FROM Sesion WHERE (dia=? AND mes=?);";	return consulta;}

I need to be able to call this method with (dia, mes).

Link to comment
https://linustechtips.com/topic/487703-java-mysql-throught-jdbc-listvo-error/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×