Ciao a tutti, vi spiego il mio problema.
la mia applicazione è connessa a un db derby tramite hibernate. quando faccio una query hql tra gli elementi da restituire c'è una data che è in formato date nel db.
come faccio a convertirla?la mia funzion è la seguente e il metodo di parser da me immesso mi da errore, AIUTATEMI PLEASE!
public List<InfoPrestiti> getAllPrestiti(){
List list = null;
Session session = null;
List<InfoPrestiti> listP = new ArrayList<InfoPrestiti>();
try {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
session = sessionFactory.openSession();
String stato="restituito";
String query = "";
query = " select u.nome, u.cognome, l.titolo, g.genere, e.nome, p.data_prestito, " +
" from Prestito p, Utente u, Libro l, Genere g, Editore e " +
" where p.username_utente = u.username and p.isbn_libro=l.isbn " +
" and l.codice_genere=g.codice and l.codice_editore = e.codice and p.stato='"+stato+"' ";
list = session.createQuery(query).list();
Iterator it = list.iterator();
while (it.hasNext()) {
InfoPrestiti item = new InfoPrestiti();
Object[] object = (Object[]) it.next();
item.setNomeUtente(object[0].toString());
item.setCognomeUtente(object[1].toString());
item.setTitoloLibro(object[2].toString());
item.setGenere(object[3].toString());
item.setNomeEditore(object[4].toString());
DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date date = (Date)formatter.parse((String) object[5]);
item.setDataPrestito(date);
listP.add(item);
}
return listP;
} catch (Exception e) {
return listP;
} finally {
if (session != null)
session.close();
}
|