-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to display data from database
PostPosted: Fri Feb 23, 2007 3:25 am 
Newbie

Joined: Mon Feb 19, 2007 6:31 am
Posts: 12
Hi

Can someone help please?
I have a connection to my Posrgresql database.
How do i display the data that is contained in my list?
the part in bold does not work and give the error:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select name from NAMES
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object;
at hello.HelloWorld.main(HelloWorld.java:25)
5 message(s) found:

//this is part of my code.
Session newSession =HibernateUtil.currentSession ().getSessionFactory().openSession();
Transaction newTransaction = newSession.beginTransaction();
List messages = newSession.createSQLQuery("select name from NAMES").list();

//this tells me that my query found n items in the table
System.out.println( messages.size() + " message(s) found:" );

for ( Iterator iter = messages.listIterator();iter.hasNext(); )
{
NAMES loadedMsg = (NAMES) iter.next();
System.out.println( loadedMsg.getText() );
}
newTransaction.commit();
newSession.close();


//this is my NAMES class

package hello;

public class NAMES {
private long id;
private String text;
private NAMES nextMessage;

NAMES()
{

}

public NAMES(String text)
{
this.text = text;
}

public Long getId()
{
return id;
}

private void setId(Long id)
{
this.id = id;
}

public String getText()
{
return text;
}

public void setText(String text)
{
this.text = text;
}

public NAMES getNextMessage()
{
return nextMessage;
}

public void setNextMessage(NAMES nextMessage)
{
this.nextMessage = nextMessage;
}


}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 23, 2007 3:47 am 
Beginner
Beginner

Joined: Mon Jan 22, 2007 1:16 pm
Posts: 21
Which line in your code does the exception point to? The exception says
(HelloWorld.java:25), but which line is that?


I don't know if this will help you, but in my code i use an iterator :

for (Iterator iter = messages.iterator(); iter.hasNext();)


In your code, you have a listIterator:

for (Iterator iter = messages.listIterator(); iter.hasNext();)


regards,
Mark


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.