aspose file tools*
The moose likes JDBC and the fly likes How can i pass valid email address as a prarameter value in sql query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How can i pass valid email address as a prarameter value in sql query " Watch "How can i pass valid email address as a prarameter value in sql query " New topic
Author

How can i pass valid email address as a prarameter value in sql query

sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
hi to all,
MembersTable -- this is dbtable contails Email,name,pan etc fields.
1)before passing email as a parameter to the query i validate the email address.And store that value in one string say emailidvalue,

2)rs=st.executeQuery
("select Name,Email from MembersTable where Email like '"+emailidvalue+"' ");

it is not working am i doing in right path..
please help me
thanks in advance.
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

What error are you getting. elaborate it further.


Ashwin Sridhar
SCJP | SCWCD | OCA
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
first of all thanks for repling my post,
actually my requirment is setting email value dynamically.
first i am trying to do in static manar that is i am fixing the email value as String se="sudheer@ca.com"; This is "se" value may sent to the query as a paramater value.
In database also Email is stored like this only(sudheer@ca.com)
query is :
rs=("select Name,Email from MembersTable where Email like '"+se+"' ");
out put : nothing will come .

is it use any regular expression related values in the query please help me ..
thanks in advance..


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
For starters, use PreparedStatement. Cobbling together SQL statements with string concatenation is fraught with problems.

Secondly, does "se" contain percentage signs? If not, using "like" provides no benefit except to slow down the query, and you should use "=" instead.

Lastly, if a query doesn't return the results you expect, I'd start by running it directly against the DB (with whatever command-line or GUI tool you usually use to interact with the DB).


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i pass valid email address as a prarameter value in sql query