By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

Validating the SQL Query entered by user using Java Script

P: 11
I have a textarea in my jsp, where in the user will enter a sql query of select or insert or update or delete.I have to validate that entered data and say whether the query is syntatically correct or not.For Example if User enters,
Select * from Tab..:
like this, it has to throw an alert message saying that, sql query is invalid as the user entered ..: at the end of the query.

I have to do this in javascript.
Can any one help me out?

Thanks&Regards
Anuradha
Jan 23 '08 #1
Share this Question
Share on Google+
13 Replies


BigDaddyLH
Expert 100+
P: 1,216
Since you have to do this in JavaScript, it is not a Java problem, now is it? On the other hand, what if the user turns off scripting in their browser?
Jan 23 '08 #2

acoder
Expert Mod 15k+
P: 16,027
This is not a trivial task! You will have to parse the input and check for mis-spellings, syntax errors and lots more. Perhaps you should make a few basic checks instead.
Jan 23 '08 #3

acoder
Expert Mod 15k+
P: 16,027
what if the user turns off scripting in their browser?
You can make checks on the client-side as a backup (and it saves a trip to the server just to be met with an error message). The real checking should always be made on the server-side, of course.
Jan 23 '08 #4

BigDaddyLH
Expert 100+
P: 1,216
You can make checks on the client-side as a backup (and it saves a trip to the server just to be met with an error message). The real checking should always be made on the server-side, of course.
Indeed. Me, I always turn off JavaScript. Speeds up the browser ;-)
Jan 23 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Indeed. Me, I always turn off JavaScript. Speeds up the browser ;-)
You don't know what you're missing! ;)

JavaScript does have its uses, just that sometimes it's misused. It's not like what it used to be, though.
Jan 24 '08 #6

P: 11
Can you please let me know the example or send a sample code?
Jan 29 '08 #7

acoder
Expert Mod 15k+
P: 16,027
For validation, you can use regular expressions. Post your code so far.
Jan 30 '08 #8

P: 11
till now i didn't started any coding on this.i have yet to start.Thought i will get some idea to proceed and theni can start
Jan 30 '08 #9

acoder
Expert Mod 15k+
P: 16,027
The first step is to add an onsubmit to the form:
[html]<form ... onsubmit="return validate(this);">[/html]

Then your validation function would return true if it passes validation and false otherwise.

What exactly are you checking?
Jan 30 '08 #10

P: 11
The first step is to add an onsubmit to the form:
[html]<form ... onsubmit="return validate(this);">[/html]

Then your validation function would return true if it passes validation and false otherwise.

What exactly are you checking?

i got that functonality.. thank you.....
Feb 7 '08 #11

acoder
Expert Mod 15k+
P: 16,027
i got that functonality.. thank you.....
Glad to hear that you got it working. Can you post your solution here for the benefit of others.

PS. I split your other posts into a new thread.
Feb 7 '08 #12

P: 11
Glad to hear that you got it working. Can you post your solution here for the benefit of others.

PS. I split your other posts into a new thread.

i did it thrrought backend..means, once the user enter the sql in text box, am executing the query in DAO and if the query returns any records or not with out error, then it is a valid query.Else am throwing the exception that query is not valid.
Feb 8 '08 #13

acoder
Expert Mod 15k+
P: 16,027
i did it thrrought backend..means, once the user enter the sql in text box, am executing the query in DAO and if the query returns any records or not with out error, then it is a valid query.Else am throwing the exception that query is not valid.
Thanks for that. Yes, that would be the preferred way in this case (though you could make an XMLHttp [Ajax] request using JavaScript.
Feb 8 '08 #14

Post your reply

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