• Post Reply Bookmark Topic Watch Topic
  • New Topic

string value

 
mike shin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my data field 'name' have a colon (exampe :M'MOHAN). im using a string value like
-String name="";
-String name = request.getParameter("name");
but i cannot save and came out with error. It is because it have a colon.
i want to know what type of value that i can use or it is someting else that i have to add.
TQ
 
Nitin Pathak
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pre-parse your String replacing the single quote (or a regular expression) with the subsequent escape character (in your case, it is \').
 
mike shin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where should i put these \'. im still not understand
 
Nitin Pathak
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JVM would understand the single quote (') if this is escaped, or your name is presented as M\'MOHAN. Hence, you need to modify your current String with an escape character:
;
 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to reinvent the whele, you could use the StringEscapeUtils from commons-lang http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml(java.lang.String)

Regards,
Uli
 
Nitin Pathak
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Uli Hofstoetter:
If you don't want to reinvent the whele, you could use the StringEscapeUtils from commons-lang http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml(java.lang.String)

Regards,
Uli


Thanks Uli for the reference! I almost forgot about excapeXml's capabilities! :thumb:
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mike shin:
my data field 'name' have a colon (exampe :M'MOHAN). im using a string value like
-String name="";
-String name = request.getParameter("name");
but i cannot save and came out with error. It is because it have a colon.
i want to know what type of value that i can use or it is someting else that i have to add.
TQ


You insinuates it as if it was an error in String. But this is impossible.

I think you're rather talking about an error during inserting it in the database. If this is true, then you should be using PreparedStatement instead.

In the future, please do not ignore errors and talk about it as if it is unimportant: "i got an error". Tell more about them. Copypaste the complete phrase and the trace here. They contains very important information about the precise cause of the problem and the invocation history.
[ December 17, 2008: Message edited by: Bauke Scholtz ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!