|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
Try this instead
rs=statement.executeQuery("SELECT * FROM students WHERE firstname='" + request.getParameter("searchStudent") + "'"); |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
just put an AND clause in your query.
WHERE (first = first AND last = last ) OR . . . |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > using mysql and jsp to extract records |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|