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:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old February 17th, 2002, 10:47 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
using mysql and jsp to extract records

I'm new to JSP

Here is portion of my code. searchStudent refers to the name of the textfield where the first name is entered.

SQL statement.
rs=statement.executeQuery("SELECT * FROM students WHERE firstname='request.getParameter("searchStudent")'");

......

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

....

it gives me an error message
Generated servlet error:
C:\Apache Tomcat 4.0\work\localhost\Testing\searchstudent1$jsp.java:83: ')' expected.
rs=statement.executeQuery("SELECT * FROM students WHERE firstname='request.getParameter("searchStudent")'");

however can I display only those records specified in the texfield

Help

Leslie

Reply With Quote
  #2  
Old February 19th, 2002, 01:02 AM
_.M _.M is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Stockholm, Sweden
Posts: 1 _.M User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to _.M
Try this instead
rs=statement.executeQuery("SELECT * FROM students WHERE firstname='" + request.getParameter("searchStudent") + "'");

Reply With Quote
  #3  
Old February 19th, 2002, 06:21 AM
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 statement in a jsp page

Hi

Thanx for the previous suggestion, it worked. However I would like to know how to concatenate two strings 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 form students table relating
//first name, last name, first name and last name,student number
//of particular student

//Whats wrong with this statement
rs=statement.executeQuery("SELECT * FROM students WHERE first+last='" +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
  #4  
Old February 23rd, 2002, 12:28 AM
Keiichi Keiichi is offline
aHVoPw==
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,058 Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 15 h 24 m 31 sec
Reputation Power: 9
in:
"SELECT * FROM students WHERE first+last='"
is there such a column named first+last?
(you shouldn't name a column with a plus in it.. use underscore would look nicer...)
__________________
K1

Reply With Quote
  #5  
Old February 23rd, 2002, 02:50 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
just put an AND clause in your query.

WHERE
(first = first AND last = last ) OR . . .

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > using mysql and jsp to extract records


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 6 hosted by Hostway