Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

characters that crash mysql queries

Status
Not open for further replies.

mslane

Programmer
Dec 12, 2001
11
US
Hello,

I'm doing some web programming, and have run into a few issues using mysql queries. There are a number of characters (ie #%&";") that stall my queries. I'm programming in java, and I run the executeQuery command on user entered text. How can I prepare the statement to go to the database so that the query won't crash, and then how can I get the info back out.

Thanks,
Matt
 
The characters are in the query from user entered values.
For example
I would ask the question:
What is today's date?
They respond:
Today's date is December 17, 2001.

If I tried to put the user entered String into the database with this statement
String newDate = request.getParameter(enteredDate);
update examples set date = \""+ newDate +"\"";

my query would stall at the apostraphy in "Today's". Or it would stall with the comma that is in the date itself. What I've done is write a method that puts a slash in front of each of these characters. I'm just wondering if there is an easier way than running all of my query variables through this method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top