February 20th, 2002, 03:36 PM
Join Date: Feb 2002
Time spent in forums: < 1 sec
Reputation Power: 0
concatenating strings and columns in mysql query statement in a jsp page
I would like to know how to concatenate two strings and columns in the where portion in an mysql statement.
Here is a fragment of my code
/*Search student refers to the name of the textfield either student number, first name, last name, or both first name and last name*/
//the var student is the student number
//the var first is the first name
//the var last is the last name
String student = request.getParameter("searchStudent");
String first = request.getParameter("searchStudent");
String last = request.getParameter("searchStudent");
connection = DriverManager.getConnection(connectionURL, "", "");
//This statment search for all records from students table relating
//firstname, lastname, first name and last name,student number
//of particular student
//Whats wrong with this statement
rs=statement.executeQuery("SELECT * FROM students WHERE firstname+lastlastname='" +first+last+"' OR firstname='" + first + "' OR lastname='" + last + "' OR studentid='" + student + "'");
I'm getting this error
javax.servlet.ServletException: Column not found: Unknown column 'first' in 'where clause'
I want the text field to accept a full name for example "Tom Jones"
It will then search the firstname and lastname from the student table and display those records for that persons name.