dcsimg
Problems placing variables into Queries
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Justin_Denning
Posted On:   Thursday, April 24, 2003 07:45 AM

I am new to SQL and want to know how to correctly write the following query


"SELECT * FROM Customers WHERE LastName = 'lastnamevariable' "


where Customers is the database, LastName is the column name, and lastnamevariable is a string obtained from a form.


Thank you

Re: Problems placing variables into Queries

Posted By:   Brian_Glodde  
Posted On:   Thursday, April 24, 2003 07:54 AM


// retrieving the string from the form
String lastnamevariable = request.getParameter( "LastName" );
if( lastnamevariable == null ) lastnamevariable = "";

if( !lastnamevariable.equals( "" ) )
{
// concatenation for SQL query
String SQL = "SELECT * FROM Customers WHERE LastName = '" + lastnamevariable + "'"
// execute the query
}

HTH.
About | Sitemap | Contact