SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 20th, 2002, 03:36 PM
getchoo getchoo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 20 getchoo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
concatenating strings and columns in mysql query statement in a jsp page

Hi

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");

student.trim();
first.trim();
last.trim();

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "", "");
statement=connection.createStatement();

//Query statment
//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 + "'");

while (rs.next()){
String studentID=rs.getString(1);
String firstName=rs.getString(2);
String lastName=rs.getString(3);

.......

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.

Please Help

Leslie

Reply With Quote
  #2  
Old February 21st, 2002, 06:26 AM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
there is a mysql function called concat

i.e.

firstname+lastname

is equivalent to

concat(firstname, lastname)

Probably no help, but the error message doesn't make too much sense, cos you are never refering to a column as "first" this is purely in the java, so the db will not see this as it is at a different layer of abstraction

Oscagne

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > concatenating strings and columns in mysql query statement in a jsp page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway