-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to insert into a table using native SQL?
PostPosted: Mon Jun 21, 2004 10:29 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
Hi,

I've read somewhere, than hibernate supports native sql command. I've tryied an select, it worked, but
I don't know how to insert into a table.

I've tried it with 'insert into .. values', there was no error, but
the row was not inserted (i checked throug a db visualiser)
public void insertStitek(
Integer a, Integer b,
String c) {

Query sqlQuery;
String queryString =
"insert into kstitek(a,b,c) values("
+ a.intValue()
+ ","
+ b.intValue()
+ ","
+ "\'" + c + "\')";

sqlQuery = getSession().createSQLQuery(queryString, "stitky", Object.class);

List list = null;
try {
list = sqlQuery.list();
}
catch (HibernateException he) {}
}

I'm usint HibernateDaoSupport, and as I said select works, but insert doesn't


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 2:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use s.connection() if you want to do raw sql insert.

createSQLQuery() is for *query*ing not manipulation....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 8:46 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
max wrote:
use s.connection() if you want to do raw sql insert.

createSQLQuery() is for *query*ing not manipulation....


could yuo provide me a short example how to use connection() and native sql insert?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 1:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it's a standard JDBC connection!

just use it as you would normally use such a thing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.