Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sql:update - how to retrieve generated keys?  RSS feed

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

The subject is kind of explainatory, when using JSTL sql:update tag, how would you retrieve generated keys?

I know how to do it the normal programmed way, but is there a way to do it through JSTL?

Thanks!
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how you are generating keys?

tip: it is not recommended to use JSTL sql tags, though.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How? AUTO_GENERATE KEYS.

And I don't care that it's not recommended to use SQL tags, they've been working fine for me.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes they always work fine if no errors. but it is considered a bad design. anyway, i am not forcing you. it was just a tip.

and about your AUTO_GENERATE KEYS. sorry i dont know about this or may be you have to be a bit more elaborated.

thanks.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you didn't know maybe you shouldn't have replied?

I generally use sql tags for data presentation, but I had a case where it was safe to use it to insert data, so I went for it.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Safe or whatever. It is considered as a bad design. you should not write your database access code in your jsp page (presentation tier). And it is for sure.

Thanks for the suggestion. But I know when I should reply and when I should not.

Tip: Ranch is a quite friendly society. Please takecare.

thanks.
[ November 23, 2004: Message edited by: Adeel Ansari ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear looks up from wiping down the counter.

Let's keep it civil gentlemen.

Ivan, use of SQL on the JSP pages is generally considered a poor practice. Even strong proponents of the JSTL will wince a bit when the sql tags are mentioned and point out that they should only be used for quick prototyping but never for production code. Don't shoot the messenger.

Bear returns to washing glasses.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I am totally with you on it being the bad practice and all, but when I have a $400 project with hardly any programming, what the hell am I supposed to do? Fire up struts?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fire up struts?


<shudder>... heck no!

Seriously, do you find it more time and effort to write simple classes that perform JDBC? To me, that's much faster and easier to debug than trying to wrestle with it on the pages.

But my point was not to convince you to do it one particular way, just don't snap at people who are trying to steer you in a better direction.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't snap I was just saying.

And yes I do find it easy to put in

<sql:query datasource="${application.datasource}">
SELECT ID,name,age,email FROM students
</sql:query>

Rather than statements, connections, finally blocks, making sure it's not null before closing it, and all that bullcrap. Besides, its faster to recomile a JSP page than to reload all your classes.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do find it easy to put in ...


Except when you try to figure out how to do something not supported like retrieving generated keys.

In any case, your "saying" came across to me as somewhat "snappy". Just watch your tone when responding to people who are trying to help you, ok?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:

Don't shoot the messenger.


Laughing out loud.

thanks bear. I was just waiting for something exactly similar.
[ November 24, 2004: Message edited by: Adeel Ansari ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!