?
Solved

SQL Query the "AND" Statement - urgent

Posted on 2003-03-15
45
Medium Priority
?
420 Views
Last Modified: 2007-12-19
Hello :)
I have been struggling for the past 3 days to get the "and" statement to work, There is no errors in the actual program, but it is not returning the record/records. And I have made sure that the fields i am calling are present in the Access database. Where am I going wrong? Do I need an IF Statement. when i use the OR statement it works,  but i want the "hobbyname", "sex" and "coursename" values to met entirely. Please, please can you help :(

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet RS = statement.executeQuery
("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE HobbyName=? AND Sex=? AND CourseName=?");
%>
0
Comment
Question by:neks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 18
  • 14
  • 12
  • +1
45 Comments
 
LVL 3

Expert Comment

by:allahabad
ID: 8143343
Looks like, You have case problem, pass the value in either lower case or upper case.

For ex. if you want to compare with lower case.

statement.setString(1,hobbyNameValue.toLowerCase());
statement.setString(2,sexValue.toLowerCase());
statement.setString(3,courseNameValue.toLowerCase());

java.sql.ResultSet RS = statement.executeQuery
("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE lower(HobbyName)=? AND lower(Sex)=? AND lower(CourseName)=?");
0
 

Author Comment

by:neks
ID: 8144060
Thanx for replying,
I have actually tried both uppercase and lowercase, and it is coming up with 3 errors saying......."
"HobbyNameValue" is either a misplaced package name or a non-existent entity. etc.

It might be me, maybe im  coding it in the wrong place. I placed it like this...


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.Statement statement = connection.createStatement();
statement.setString(1,HobbyNameValue.toUpperCase());
statement.setString(2,SexValue.toUpperCase());
statement.setString(3,CourseNameValue.toUpperCase());
java.sql.ResultSet RS = statement.executeQuery
("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE upper HobbyName=? AND upper Sex=? AND upper CourseName=?");

0
 
LVL 92

Expert Comment

by:objects
ID: 8144698
You are not using a prepared statement (in fact I'm not sure how the above code even compiles). Try this:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE upper HobbyName=? AND upper Sex=? AND upper CourseName=?");
statement.setString(1,HobbyNameValue.toUpperCase());
statement.setString(2,SexValue.toUpperCase());
statement.setString(3,CourseNameValue.toUpperCase());
java.sql.ResultSet RS = statement.execute();



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:neks
ID: 8144889
I pasted the wrong code previously, I did use the Prepared Statement, everything seems right in the sql query, but an error comes up now saying.......

Syntax error (missing operator) in query expression 'Upper HobbyName=? AND upper Sex=? AND upper CourseName=?'.

This is how my code stands at the moment;

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE Upper HobbyName=? AND upper Sex=? AND upper CourseName=?");
statement.setString(1,"HobbyNameValue".toUpperCase());
statement.setString(2,"SexValue".toUpperCase());
statement.setString(3,"CourseNameValue".toUpperCase());
java.sql.ResultSet RS = statement.executeQuery();

so, again where is the problem? Searchinng a database is supposed to be one of the easiest things to do, but this doesnt seem to be the case:(
P.S The last line thats executes it needs to contain the word query or that comes up with an error. Please help!!!
0
 
LVL 92

Expert Comment

by:objects
ID: 8144907
should be something like this:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE HobbyName=? AND Sex=? AND CourseName=?");
statement.setString(1,hobby);
statement.setString(2,sex);
statement.setString(3,course);
java.sql.ResultSet RS = statement.executeQuery();

0
 
LVL 3

Expert Comment

by:allahabad
ID: 8144967
Little modification , since you are comparing with upper case values.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE upper HobbyName=? AND upper Sex=? AND upper CourseName=?");
// here hobby,sex,coures are Java String variables.
statement.setString(1,hobby.toUpperCase());
statement.setString(2,sex.UpperCase());
statement.setString(3,course.toUpperCase());
java.sql.ResultSet RS = statement.executeQuery();
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8144968
Little modification , since you are comparing with upper case values.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE upper HobbyName=? AND upper Sex=? AND upper CourseName=?");
// here hobby,sex,coures are Java String variables.
statement.setString(1,hobby.toUpperCase());
statement.setString(2,sex.toUpperCase());
statement.setString(3,course.toUpperCase());
java.sql.ResultSet RS = statement.executeQuery();
0
 
LVL 92

Expert Comment

by:objects
ID: 8144987
have you run the query in Access to confirm that some records actually match your query?
0
 

Author Comment

by:neks
ID: 8144996
I pasted the wrong code previously, I did use the Prepared Statement, everything seems right in the sql query, but an error comes up now saying.......

Syntax error (missing operator) in query expression 'Upper HobbyName=? AND upper Sex=? AND upper CourseName=?'.

This is how my code stands at the moment;

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE Upper HobbyName=? AND upper Sex=? AND upper CourseName=?");
statement.setString(1,"HobbyNameValue".toUpperCase());
statement.setString(2,"SexValue".toUpperCase());
statement.setString(3,"CourseNameValue".toUpperCase());
java.sql.ResultSet RS = statement.executeQuery();

so, again where is the problem? Searchinng a database is supposed to be one of the easiest things to do, but this doesnt seem to be the case:(
P.S The last line thats executes it needs to contain the word query or that comes up with an error. Please help!!!
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8145045
Access does not distinguish between upper and lower case .

So remove Upper from the code.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE HobbyName=? AND Sex=? AND CourseName=?");
// here hobby,sex,coures are Java String variables.
statement.setString(1,hobby);
statement.setString(2,sex);
statement.setString(3,course);
java.sql.ResultSet RS = statement.executeQuery();
0
 
LVL 92

Expert Comment

by:objects
ID: 8145069
> So remove Upper from the code.

Didn't you just tell neks to add it :)

That code is also identical to what I already posted.

0
 
LVL 3

Expert Comment

by:allahabad
ID: 8145102
I just came to know that Access does not distinguish between upper and lower case ,when neks posted Syntax error (missing operator) in query expression 'Upper HobbyName=? AND upper Sex=? AND upper CourseName=?'.

Yes, i did to help him.  I could have also said look to for the posting of objets. My mistake Mr. objects.
0
 
LVL 92

Expert Comment

by:objects
ID: 8145115
> when neks posted Syntax error (missing operator) in
> query expression 'Upper HobbyName=? AND upper Sex=? AND upper CourseName=?'.

He actually posted that before your comment, but u may have missed it :)

Comment from neks  03/15/2003 04:56PM PST  

0
 
LVL 3

Expert Comment

by:allahabad
ID: 8145144
Yes, you are right, I missed "Comment from neks  03/15/2003 04:56PM PST".
0
 

Author Comment

by:neks
ID: 8145215
yes I have checked numerous amounts of time that the 3 searches that i use are being satisfied in the Access database. None of the suggessted codes work
Firstly; none of the codes posted use( request.getParameter), so I am baffled has in to how the program is supposed to bring up the fields requested. It does not recognise
1)statement.setString(1,hobby);
neither does it recognise.... this method
statement.setString(1,hobby.toUpperCase());
(they both come with errors specifying that the package/method is unknown)

it however recognises the way i implement it and runs...
statement.setString(1,request.getParameter("HobbyName"));
however the specfied record does not show up, as i said when I use the OR statement it works... how weird!!do you suggest that I use an IF statement?!?
0
 

Author Comment

by:neks
ID: 8145231
dear objects and allahabad,
I am actually female ;)
0
 

Author Comment

by:neks
ID: 8145244
dear objects and allahabad,
I am actually female ;)
0
 

Author Comment

by:neks
ID: 8145256
dear objects and allahabad,
I am actually female ;)
0
 
LVL 92

Expert Comment

by:objects
ID: 8145269
> I am actually female ;)

My apologies, i generally try not to be gender specific but occasionally I slip up. Again please accept my apologies.

> none of the codes posted use( request.getParameter),

Well u never stated where the query parameters were coming from so we could only post generic code :)

> 1)statement.setString(1,hobby);

Here hobby is assumed to be a string variable containing the value of your request parameter.
So yes you should replace it with request.getParameter("HobbyName"). Same for the other query parameters.

> however the specfied record does not show up

Check the values of your request parameter.
Also what are the types of the columns in the database?
0
 

Author Comment

by:neks
ID: 8145271
sorry for repeating myself 3 times, I am a new user and not very familiar with the way this site works.
i shall check for any new code posted tomorrow, as it is 3am here in London.
Thank you..
neks
0
 

Author Comment

by:neks
ID: 8145300
In the Access database the 3 fields are all declared as text, thus I used "String", could it be the seetings in my design view in access? Bcos where it says "required data entry in the field", they are all set to "no", but I dont think that is the problem.
0
 
LVL 92

Expert Comment

by:objects
ID: 8145346
No, that shouldn't create a problem.

Perhaps try trimming the parameters:

System.out.println(request.getParameter("HobbyName"));
System.out.println(request.getParameter("Sex"));
System.out.println(request.getParameter("CourseName"));

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
java.sql.PreparedStatement statement = connection.prepareStatement ("SELECT FirstName,LastName,HobbyName,Sex,CourseName FROM Student WHERE HobbyName=? AND Sex=? AND CourseName=?");
statement.setString(1,request.getParameter("HobbyName").trim());
statement.setString(2,request.getParameter("Sex").trim());
statement.setString(3,request.getParameter("CourseName").trim());
java.sql.ResultSet RS = statement.executeQuery();



0
 

Author Comment

by:neks
ID: 8145981
Nope,
trimming the parameters brings up an error saying null pointer exception.

any more suggestions...
0
 

Author Comment

by:neks
ID: 8146897
hi,
this is how my code stands right now.... and it still isnt running.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
     String sql = ""
     + " SELECT FirstName, LastName, Age, CourseName, Sex"
     + " FROM Student"
     + " WHERE Age = ?"
     + " OR CourseName = ?"
     + " OR Sex = ?"
;
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,request.getParameter("FirstName"));
statement.setString(2,request.getParameter("LastName"));
statement.setString(3,request.getParameter("Age"));
statement.setString(4,request.getParameter("CourseName"));
statement.setString(5,request.getParameter("Sex"));
ResultSet RS = statement.executeQuery();

while(RS.next()) {
String Age = RS.getString(3);
String CourseName = RS.getString(4);
String Sex = RS.getString(5);  
%>
<table BORDER WIDTH="100%" >
<tr>
     <td><b>First Name</b></td>
     <td><b>Surname</b></td>
     <td><b>Age</b></td>
     <td><b>Course</b></td>
     <td><b>Gender</b></td>
</tr>
<%

     }
     RS.close();
connection.close();
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8146935
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
    String sql = ""
    + " SELECT FirstName, LastName, Age, CourseName, Sex"
    + " FROM Student"
    + " WHERE Age = ?"
    + " OR CourseName = ?"
    + " OR Sex = ?"
;
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(3,request.getParameter("Age"));
statement.setString(4,request.getParameter("CourseName"));
statement.setString(5,request.getParameter("Sex"));
ResultSet RS = statement.executeQuery();

<table BORDER WIDTH="100%" >
<tr>
    <td><b>First Name</b></td>
    <td><b>Surname</b></td>
    <td><b>Age</b></td>
    <td><b>Course</b></td>
    <td><b>Gender</b></td>
</tr>
while(RS.next()) {
String firstName = RS.getString(1);
String lastName = RS.getString(2);
String Age = RS.getString(3);
String CourseName = RS.getString(4);
String Sex = RS.getString(5);  
%>
<table BORDER WIDTH="100%" >
<tr>
    <td><%= firstName %></td>
    <td><%= lastName %></td>
    <td><%= Age %></td>
    <td><%= CourseName %></td>
    <td><%= Sex %></td>
</tr>
<%

    }
    RS.close();
connection.close();


Make sure your request Paremter name (Age,CourseName,Sex) are correct
in case also.
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8146948
There was little mistake in setString.
try this:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
    String sql = ""
    + " SELECT FirstName, LastName, Age, CourseName, Sex"
    + " FROM Student"
    + " WHERE Age = ?"
    + " OR CourseName = ?"
    + " OR Sex = ?"
;
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,request.getParameter("Age"));
statement.setString(2,request.getParameter("CourseName"));
statement.setString(3,request.getParameter("Sex"));
ResultSet RS = statement.executeQuery();

<table BORDER WIDTH="100%" >
<tr>
    <td><b>First Name</b></td>
    <td><b>Surname</b></td>
    <td><b>Age</b></td>
    <td><b>Course</b></td>
    <td><b>Gender</b></td>
</tr>
while(RS.next()) {
String firstName = RS.getString(1);
String lastName = RS.getString(1);
String Age = RS.getString(3);
String CourseName = RS.getString(4);
String Sex = RS.getString(5);  
%>
<table BORDER WIDTH="100%" >
<tr>
    <td><%= firstName %></td>
    <td><%= lastName %></td>
    <td><%= Age %></td>
    <td><%= CourseName %></td>
    <td><%= Sex %></td>
</tr>
<%

    }
    RS.close();
connection.close();


Make sure your request Paremter name (Age,CourseName,Sex) are correct
in case also.
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8146983
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
    String sql = ""
    + " SELECT FirstName, LastName, Age, CourseName, Sex"
    + " FROM Student"
    + " WHERE Age = ?"
    + " OR CourseName = ?"
    + " OR Sex = ?"
;
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,request.getParameter("Age"));
statement.setString(2,request.getParameter("CourseName"));
statement.setString(3,request.getParameter("Sex"));
ResultSet RS = statement.executeQuery();
%>

<table BORDER WIDTH="100%" >
<tr>
    <td><b>First Name</b></td>
    <td><b>Surname</b></td>
    <td><b>Age</b></td>
    <td><b>Course</b></td>
    <td><b>Gender</b></td>
</tr>
<%
while(RS.next()) {
String firstName = RS.getString(1);
String lastName = RS.getString(1);
String Age = RS.getString(3);
String CourseName = RS.getString(4);
String Sex = RS.getString(5);  
%>

<tr>
    <td><%= firstName %></td>
    <td><%= lastName %></td>
    <td><%= Age %></td>
    <td><%= CourseName %></td>
    <td><%= Sex %></td>
</tr>
<%

    }
%>
</table>
<%
    RS.close();

connection.close();
%>

Make sure your request Paremter name (Age,CourseName,Sex) are correct
in case also.

If this does not work, could you post us error message of the page.
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8146994
<%@ page import="java.sql.*" %>
// make sure imported required classes
<%
try {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
    String sql = ""
    + " SELECT FirstName, LastName, Age, CourseName, Sex"
    + " FROM Student"
    + " WHERE Age = ?"
    + " OR CourseName = ?"
    + " OR Sex = ?"
;
java.sql.PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1,request.getParameter("Age"));
statement.setString(2,request.getParameter("CourseName"));
statement.setString(3,request.getParameter("Sex"));
ResultSet RS = statement.executeQuery();
%>

<table BORDER WIDTH="100%" >
<tr>
    <td><b>First Name</b></td>
    <td><b>Surname</b></td>
    <td><b>Age</b></td>
    <td><b>Course</b></td>
    <td><b>Gender</b></td>
</tr>
<%
while(RS.next()) {
String firstName = RS.getString(1);
String lastName = RS.getString(1);
String Age = RS.getString(3);
String CourseName = RS.getString(4);
String Sex = RS.getString(5);  
%>

<tr>
    <td><%= firstName %></td>
    <td><%= lastName %></td>
    <td><%= Age %></td>
    <td><%= CourseName %></td>
    <td><%= Sex %></td>
</tr>
<%

    }
%>
</table>
<%
    RS.close();

connection.close();
}
catch (Exception e){

   out.println(e.getMessage());
}
%>

0
 
LVL 92

Expert Comment

by:objects
ID: 8147868
> trimming the parameters brings up an error saying null pointer exception.

Then the problem is that one of the request parameters is not set. ie. it is null.

Check that you arfe passing the request parameters correctly.
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8151192
insted of using Statement use preparedStatement and set the value for each "?" using setInt(), setString()..related functions.
0
 

Author Comment

by:neks
ID: 8154520
To allahabad, the code seems fine, no errors, but does not bring up the record. If I change the "AND" to "OR", it then lists all the females or males in the database. depending on which gender I have specfied. Obviously this is not what I want to achieve, thus there cant be anything wrong with the actual Access database. I have run out of ideas on what could be wrong with it.

To Objects, the request parameters are right, I have checked them over several times :(

To umangioshi, would you like to elaborate on what your saying, by using my code that I have pasted thanx :)
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8154796
i feel Age field could be giving problem  in AND condition.  So pass Age as Int .

<%@ page import="java.sql.*" %>
            // make sure imported required classes
<%
            try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Student_db","","");
               String sql = ""
               + " SELECT FirstName, LastName, Age, CourseName, Sex"
               + " FROM Student " 
               + "  WHERE Age = ?"
               + "  AND CourseName = ?"
               + "  AND Sex = ?"
            ;
            java.sql.PreparedStatement statement = connection.prepareStatement(sql);
            statement.setInt(1,Integer.parseInt(request.getParameter("Age")));
            statement.setString(2,request.getParameter("CourseName"));
            statement.setString(3,request.getParameter("Sex"));
            ResultSet RS = statement.executeQuery();
   %>

            <table BORDER WIDTH="100%" >
            <tr>
               <td><b>First Name</b></td>
               <td><b>Surname</b></td>
               <td><b>Age</b></td>
               <td><b>Course</b></td>
               <td><b>Gender</b></td>
            </tr>
            <%
            while(RS.next()) {
            String firstName = RS.getString(1);
            String lastName = RS.getString(1);
            String Age = RS.getString(3);
            String CourseName = RS.getString(4);
            String Sex = RS.getString(5);  
            %>

            <tr>
               <td><%= firstName %></td>
               <td><%= lastName %></td>
               <td><%= Age %></td>
               <td><%= CourseName %></td>
               <td><%= Sex %></td>
            </tr>
            <%

               }
            %>
            </table>
            <%
               RS.close();

            connection.close();
            }
            catch (Exception e){

              out.println(e.getMessage());
            }
            %>
0
 
LVL 92

Expert Comment

by:objects
ID: 8155018
> To Objects, the request parameters are right, I have checked them over several times :(

How have you checked them?
If one of the following lines is causing an NPE, then the request parameter must be null.

statement.setString(1,request.getParameter("HobbyName").trim());
statement.setString(2,request.getParameter("Sex").trim());
statement.setString(3,request.getParameter("CourseName").trim());


0
 
LVL 3

Expert Comment

by:allahabad
ID: 8155310
I agree with 'objects'. Please check all your request parameters values and their length; this will help you to debug your problem, since you are very near to it.
Put these lines just below the try block and before JDBC class loading lines to see actually what are you getting from calling jsp.
   
     out.println("Value of Age  " +request.getParameter("Age"));
     out.println("Length of Age  " +request.getParameter("Age").length());
     out.println("Value of CourseName  " +request.getParameter("CourseName"));
     out.println("Length of CourseName  " +request.getParameter("CourseName").length());

    // looks like you are geting value of 'Sex' correct, but still just print it for your information.
     out.println("Value of Sex  " +request.getParameter(Sex"));
     out.println("Length of Sex  " +request.getParameter("Sex").length());

If you are  getting additional black spaces(in start or last), you can use 'objects' posting to trim those blank spaces, before   passing  those to sql where condition.
0
 
LVL 92

Expert Comment

by:objects
ID: 8155380
Yes, I suggested earlier printing out the request values :)
0
 

Author Comment

by:neks
ID: 8158121
yes,
there are null values present. In Age, and in HobbyName.
In HobbyName when the program runs it just says.....

"Value of HobbyName null null", i do not know much jsp, so how do i rectify this problem... I have no idea.
0
 
LVL 92

Expert Comment

by:objects
ID: 8158128
Check the page that is calling it is setting/passing the parameters correctly.
0
 

Author Comment

by:neks
ID: 8158970
Guess what? I think I know where my problem is. I didnt actually show any of you (allahabad and objects), where I was calling the page from. I havent set the Parameters on this page to retreive "HobbyName", "CourseName", and "Sex", this is the file (below). I am not sure how to either, so I'll experiment, with it whilst I wait for your professional advice :)
This is where I search from, and it calls the page that we have been working on... I hope this helps to find out where Ive been going wrong.

<font size="5" color="#003366"><b>Student  - Search </b></font>
<form name="HobbySearch" method="Post" action="Three2.jsp">
<table border="0" cols="2" width="75%" >
<tr>
       <td width="25%"><b>Search by Hobby:</b></td>
     <td>
          <select name="HobbyName">
               <option>     </option>
               <option>Basketball</option>
               <option>Cooking</option>
               <option>Dancing</option>
               <option>Football</option>
               <option>Golf</option>
               <option>Horse riding</option>
               <option>Music</option>
               <option>NetBall</option>
               <option>StampCollecting</option>
               <option>Swimming</option>
          </select>
         
     </td>
</tr>
</table>
</form>
<form name="CourseSearch" method="Post" action="Three2.jsp">
<table border="0" cols="2" width="75%" >
<tr>
       <td width="25%"><b>Search by Course:</b></td>
     <td>
       <select name="CourseName">
       <option>          </option>
       <option>Aerospace</option>
       <option>Architecture</option>
       <option>Art</option>
       <option>Applied Science</option>
       <option>Biology</option>
       <option>Business</option>
       <option>Chemistry</option>
       <option>Computer Science</option>
       <option>Digital Media Studies</option>
       <option>English</option>
       <option>Economics</option>
       <option>French</option>
       <option>Geography</option>
       <option>GIS</option>
       <option>History</option>
       <option>Information Technology</option>
       <option>Law</option>
       <option>Mathematics</option>
       <option>Music</option>
       <option>Pharamacutical Science</option>
       <option>Religious Studies</option>
       <option>Sociology</option>
       <option>Spanish</option>
       <option>Sport Science</option>
       </select>
     </td>
</tr>
</table>
</form>
<form name="SexSearch" method="Post" action="Three2.jsp">
<table border="0" cols="2" width="75%" >
</tr>
<td width="28%">Sex:</td>
     <td width="72%">
       <input type="radio" name="Sex" value="Female" checked>
       Female
       <input type="radio" name="Sex" value="Male">
       Male</td>
    </tr>
    <tr>
         

</td>
</tr>
</table>
<input type="submit" name="Search" value="Search">
</form>
0
 

Author Comment

by:neks
ID: 8158985
Thanx objects, Ive only seen your reply now :)
0
 
LVL 3

Accepted Solution

by:
allahabad earned 200 total points
ID: 8159772
You need to have only one form , In your case only last form is getting submitted and it has 'Sex' field in it. That is why you were only getting the value for 'Sex' fielsd

Try this as your calling program for the jsp..
<form name="CourseSearch" method="Post" action="Three2.jsp">
            <table border="0" cols="2" width="75%" >
               <tr>
                     <td width="25%"><b>Search by Hobby:</b></td>
                   <td>
                        <select name="HobbyName" maxlength="10">
                             <option value="Basketball">Basketball
                             <option value="Cooking">Cooking
                             <option value="Dancing">Dancing
                             <option value="Football">Football
                             <option value="Golf">Golf
                             <option value="Horse riding">Horse riding
                             <option value="Music">Music
                             <option value="NetBall">NetBall
                             <option value="StampCollecting">StampCollecting
                             <option value="Swimming">Swimming
                        </select>

                   </td>
               </tr>

            <tr>
                  <td width="25%"><b>Search by Course:</b></td>
                <td>
                  <select name="CourseName" maxlength="10">
                  <option value="Aerospace">Aerospace
                  <option value="Architecture">Architecture
                  <option value="Art">Art
                  <option value="Applied Science">Applied Science
                  <option value="Biology">Biology
                  <option value="Business">Business
                  <option value="Chemistry">Chemistry
                  <option value="Computer Science">Computer Science
                  <option value="Digital Media Studies">Digital Media Studies
                  <option value="English">English
                  <option value="Economics">Economics
                  <option value="French">French
                  <option value="Geography">Geography
                  <option value="GIS">GIS
                  <option value="History">History
                  <option value="Information Technology">Information Technology
                  <option value="Law">Law
                  <option value="Mathematics">Mathematics
                  <option value="Music">Music
                  <option value="Pharamacutical Science">Pharamacutical Science
                  <option value="Religious Studies">Religious Studies
                  <option value="Sociology">Sociology
                  <option value="Spanish">Spanish
                  <option value="Sport Science">Sport Science
                  </select>
                </td>
            </tr>
            <tr>
               <td width="28%">Sex:</td>
                <td width="72%">
                  <input type="radio" name="Sex" value="Female" checked>
                  Female
                  <input type="radio" name="Sex" value="Male">
                  Male
                </td>

            </tr>


            </table>
            <input type="submit" name="Search" value="Search">
            </form>


0
 

Author Comment

by:neks
ID: 8159899
ITS WORKED!!!!
THANK YOU SO MUCH. YOU HAVE MADE MY DAY ALLAHABD :) THANK YOU A MILLION.

P.S HOW DO I GRADE YOU

P.S I HAVE TO ALSO PERSONALLY THANK OBJECTS. YOU WERE SUCH A GREAT HELP TOO

THANK YOU BOTH, FOR GOING OUT YOUR WAY TO HELP ME. PLEASE LET ME KNOW HOW TO GRADE YOU BOTH.
0
 

Author Comment

by:neks
ID: 8159939
As i said previously you were great. you responded to all my problems, and if i had used my brain, i would have sent my other page sooner, in order for you to have sussed it out.again Thank you so much, I am truly grateful.

neks xxx
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8160158
You are welcome. I think you can post it 'Community Service' section to give points for 'objects'.
0
 

Author Comment

by:neks
ID: 8160268
> To objects

please let me know how to give you points even though i posted allahabad's comment as an answer, how can I award you points and grade you as well. I have 25 points left in my account so if i need to give you those cos Ive already processed my question i truly dont mind. Please please let me know

neksxx
0
 
LVL 92

Expert Comment

by:objects
ID: 8162668
That's ok, keep your points for another question :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question