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.  [ 1 post ] 
Author Message
 Post subject: How to select data from PostgreSQL database?
PostPosted: Thu Feb 22, 2007 7:45 am 
Newbie

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

Can someone please help? i'm trying to select data from a table in PostgreSQL. My table in PostgreSQL is called NAMES and already has some data in it. how do i retrieve that data?

this is my hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">"jdbc:postgresql://tren-sa-dev"</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">admin01</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">delete</property>

<mapping resource="Message.hbm.xml"/>

</session-factory>

</hibernate-configuration>

and this is my Message.hbm.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">"jdbc:postgresql://tren-sa-dev"</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">admin01</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<mapping resource="Message.hbm.xml"/>

</session-factory>

</hibernate-configuration>


My java class is:

package hello;

import java.util.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.hibernate.util.*;
import org.hibernate.Session;
import java.util.logging.*;
import org.hibernate.dialect.PostgreSQLDialect;



//import persistence.*;
public class HelloWorld {
public static void main(String[] args) {
// First unit of work
Session session = HibernateUtil.currentSession().getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
NAMES message = new NAMES();
Long msgId = (Long) session.save(message);
tx.commit();
session.close();
Session newSession =HibernateUtil.currentSession().getSessionFactory().openSession();
Transaction newTransaction = newSession.beginTransaction();
List messages =
newSession.createQuery("from NAMES").list();
System.out.println( messages.size() + " message(s) found:" );

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

// Shutting down the application
HibernateUtil.closeSession();
}
}


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

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.