-->
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: Selection query not executing from oracle thin database.
PostPosted: Fri Jul 25, 2008 7:46 am 
Newbie

Joined: Fri Jul 25, 2008 4:34 am
Posts: 4
/*****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 name="session">
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@172.16.31.25:1521:BOMBAY</property>
<property name="hibernate.connection.username">poonam</property>
<property name="hibernate.connection.password">poonam</property>
<!-- Set AutoCommit to true -->
<property name="connection.autocommit">true</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>




//**********contact.hbm.xml**********

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="indiabulls.test.Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="sequence"/>
</id>

<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>



//**********(Getter setter) Contact.java**************

package indiabulls.test;

public class Contact
{
private String firstName;
private String lastName;
private String email;
private int id;
/*
public String getEmail()
{
return email;
}

public String getFirstName()
{
return firstName;
}

public String getLastName()
{
return lastName;
}

public void setEmail(String string)
{
email = string;
System.out.println("email==="+email);
}

public void setFirstName(String string)
{
firstName = string;
System.out.println("firstName==="+firstName);
}
public void setLastName(String string)
{
lastName = string;
System.out.println("lastName==="+lastName);

}


public int getId()
{
return id;
}

public void setId(int l)
{
id = l;
System.out.println("id ==="+id );
}
*/
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
}


///************** .java file***************


package indiabulls.test;

import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
public class SelectExample
{
public void getdata()
{ Session session = null;
try
{
System.out.println("lj;kj");
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("********CONNECTION MADE***********");
String SQL_QUERY = "Select c.firstName, c.lastName, c.email, c.id from Contact c where c.id =1";
//String SQL_QUERY = "from indiabulls.test.Contact contact";

Query query = session.createQuery(SQL_QUERY);
System.out.println("1");
System.out.println("SQL_QUERY---: "+SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();)
{
Object[] row=(Object[]) it.next();
System.out.println("1");
System.out.println("id--: " + row[0]);//it.next());
System.out.println("FirstName --: " + row[1]);//it.next());
System.out.println("LastName --: " + row[2]);
System.out.println("email --: " + row[3]);
}

System.out.println("2");
session.close();
//return "true";
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}

/* Query query = session.createQuery(SQL_QUERY);
System.out.println("SQL_QUERY : "+SQL_QUERY);
//Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();)
{
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[0]);
System.out.println("FirstName: " + row[1]);
System.out.println("LastName: " + row[2]);
System.out.println("email: " + row[3]);
}

/*Iterator it=query.iterate();
while(it.hasNext())
{
//System.out.println("******* " +it.next());
Contact contact=(Contact)it.next();
// Object[] row = (Object[]) it.next();
System.out.println("ID: " + contact.getId());
System.out.println("LastName: " + contact.getLastName());
System.out.println("Email: " + contact.getEmail());
}
System.out.println("*******Done********");
session.close();
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}*/

public static void main(String[] args)
{
SelectExample s=new SelectExample();
s.getdata();
}

}


error i am facing is :
could not execute query using iterate

please help me...i think the query i have written is not correct..as i am using thin client for oracle.....

thanks in advance...i will be obliged...........

_________________
poonam


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.