• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JSTL getparameter to int  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello together,

JSTL makes me crazy! I want to do something very simple but i cant. I get parameter from index.jsp an want to insert these parameter in an SQL table but i always get the error, that the variable "id" is char and the tablerow needs integer.

this is my code:
<c:set var="id" value= "<%= request.getParameter("id") %>"/>
<c:set var="name" value= "<%= request.getParameter("name") %>"/>
<c:set var="email" value= "<%= request.getParameter("email") %>"/>
<c:set var="titel" value= "<%= request.getParameter("titel") %>"/>
<c:set var="inhalt" value= "<%= request.getParameter("inhalt") %>"/>

<sql:update dataSource="${snapshot}" var="result">
INSERT INTO APP."forum" ("ANTWORT_ID","ANTWORT","NAME","MAIL","TITEL","INHALT","ZEIT") VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp)
</sql:update>

Error i get:
javax.servlet.ServletException:
INSERT INTO APP."forum" ("ANTWORT_ID","ANTWORT","NAME","MAIL","TITEL","INHALT","ZEIT") VALUES('3',false,'test','test','test','test',current_timestamp)
: Spalten vom Typ 'INTEGER' dürfen keine Werte des Typs 'CHAR' enthalten.

I hope someone here can help me :*>
 
Master Rancher
Posts: 4078
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing it's the number you are trying to INSERT for ANTWORT_ID.
You've put quotes around it.
 
Zet Su
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello dave,

do you mean the quotes here <c:set var="id" value= "<%= request.getParameter("id") %>"/> ?
or do you mean them here
VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp) ?

When i use c:out and print the request.getParameter or "id", there is only a number (without quotes!).
 
Sheriff
Posts: 67260
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth are you mixing JSTL and EL with scriptlet expressions? That's nuts.

Instead of <c:set var="id" value= "<%= request.getParameter("id") %>"/> just use ${param.id}
 
Bear Bibeault
Sheriff
Posts: 67260
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it is not advisable to use the sql JSTL tags in production JSP pages. Follow correct MVC.
 
Dave Tolls
Master Rancher
Posts: 4078
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zet Su wrote:Hello dave,

do you mean the quotes here <c:set var="id" value= "<%= request.getParameter("id") %>"/> ?
or do you mean them here
VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp) ?

When i use c:out and print the request.getParameter or "id", there is only a number (without quotes!).



Here:

You've added quotes.

But you should listen to Bear, the JSP is not the place to be doing any of this.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!