473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Single Quotes in select Query

snowfall
Hi all,

Am trying to retrive data from database with a where clause. The Where condition value is got from the jsp page on submission. This Value contains single quote..

Expand|Select|Wrap|Line Numbers
  1. stmt4=con.prepareStatement("select question_no from forumquestions where question_name='"+question+"'")
Here question is the variable coming from the jsp and its value is " What is 'Session Tracking' ?"

Can you help me in this....

TIA
Jan 7 '08 #1
4 2323
rpnew
188 100+
Hi all,

Am trying to retrive data from database with a where clause. The Where condition value is got from the jsp page on submission. This Value contains single quote..

Expand|Select|Wrap|Line Numbers
  1. stmt4=con.prepareStatement("select question_no from forumquestions where question_name='"+question+"'")
Here question is the variable coming from the jsp and its value is " What is 'Session Tracking' ?"

Can you help me in this....

TIA
Hi,
Why are you using string to retrieve data from table?? why aren't you using id??
it will solve your problem of quotes in value.

Regards,
RP
Jan 7 '08 #2
mwasif
802 Expert 512MB
You need to add \ before single quote. e.g. the resultant string should be
Expand|Select|Wrap|Line Numbers
  1. What is \'Session Tracking\' ?
Jan 7 '08 #3
You need to add \ before single quote. e.g. the resultant string should be
Expand|Select|Wrap|Line Numbers
  1. What is \'Session Tracking\' ?
So i have to modify my variable to include a backslash before my quotes right??
Thanks...
Will implement it in my code....
Jan 8 '08 #4
mwasif
802 Expert 512MB
Yes, you have to implement this in your code.
Jan 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: WC Justice | last post by:
I'm assuming this can be done, but I can't seem to get it to work... I'd like to easily return a single value from a sql statement, something like: "intNewItems = conn.execute "SELECT COUNT...
1
by: billmiami2 | last post by:
I'm trying to pass through a SQL statement to an Oracle database using OPENROWSET. My problem is that I'm not sure of the exact syntax I need to use when the SQL statement itself contains single...
5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
4
by: Greg | last post by:
I keep getting an error when I have a tick mark in a text value that I am searching for in my XPath Query. Example: <Authors> <Author LastName="O'Donnel"> <Author LastName="Smith">...
6
by: SStory | last post by:
How can I handle the user entering single quotes like in Bob's mini mart? If I use command objects will this no longer be an issue? I guess that would mean no simple adhoc SQL statements...
4
by: Mitchell Vincent | last post by:
Is there some built in functionality to escape special characters for use through ADO? I'm sure I could manually replace the ' with ' (if that is the right escape sequence), but I'm afriad I just...
11
by: Elmo | last post by:
Hi all! I am not very proud to ask this but here is my problem: string code = "\'13\'" The string code will have to contain following info: '51','52','63','other'... to get certain info...
2
by: thecoolone | last post by:
I am stuck at a wierd problem. I am trying to do comparision between a "query string" and a "string value". the string consists of some diacriticals and single quotes. But when i try to escape the...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
4
by: pavanponnapalli | last post by:
hi, I need to send some values to a subroutine where i use insert query. suppose say my scalar is as follows: my ($name,$number,$address) etc and i get the values into those...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.