• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP SQL String: Too long?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I execute this string (I have it entered as one line):

String command = ("INSERT INTO customer (custID, firstName, middleName, lastName, street, city, state, zipcode, homePhone, cellPhone, DOB, profession, agentID, employer, referrer) VALUES ('"+custID+"','"+firstName+"','"+middleName+"','"+lastName+"','"+street+"','"+city+"','"+state+"','"+zipcode+"','"+homePhone+"','"+cellPhone+"','"+DOB+"','"+profession+"','"+agentID+"','"+employer+"','"+referrer+"')");

I get this exception:

org.apache.jasper.JasperException: An exception occurred processing JSP page

But when I cut the string in half (only insert about half of the fields) everything works. Is there a max lenght for a String? Is there another option?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, there is not a maximum length for a String. Is it possible one of the variables has a special character or the quotes are wrong?

Note that it is bad practice to have Java code in a JSP. Extracting this code to a Java class would help. And get rid of this problem.
 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the pointer.

It turns out that one of my values (the date) was in the wrong format.

I'll certainly consider your suggestion to use a class. Right now I'm "knee deep" in this with a deadline looming and I'm scared to change gears at this point....
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And while you're refactoring, you should consider using a PreparedStatement. You say you don't have time to do that now; if you had done it before, you
wouldn't have had the error caused by the date format, because you wouldn't have had to format any dates.

I do recommend doing the refactoring sooner rather than later (i.e. before that code goes into production) as generating queries the way you have done it
leaves you open to SQL injection attacks.

 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're both right. I need to spend the time to make this right.

This is actually a project for a school assignment so I want to make sure that I learn the proper way to do this. Can either of you suggest a good place that discusses the advantages/disadvantages of JSP vs. a java class? (My book does not go into the details) To me, they are simply two different ways to get the same result. In fact, when I first read Jeanne's response my initial thought was "both ways require the same code (written a little different) so what's the big deal". I still have a lot to learn
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can either of you suggest a good place that discusses the advantages/disadvantages of JSP vs. a java class?



Certainly this question is out of concern here, if you have known a difference between web applications[made of Servlets and JSPs,run on some server] and stand alone applications[No Server side code,run locally and data is fetched locally if any],this question won't have been raised here.Actually this is not a question of any advantage/disadvange.These are used to serve two completely different purposes.Here I am providing a link to understand the differences.Feal free to query.

Link
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this article will help.
 
Bradly Fackrell
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to both of you!

I liked your article Bear. Your theory about always improving holds true in other professions as well. I’ve been a mechanical engineer for 20 years now and I still don’t feel like I’ve mastered my skills. There is always room to learn more.

I truly appreciate people like you who are willing to share their knowledge and experiences.
 
reply
    Bookmark Topic Watch Topic
  • New Topic