JSP code to return no values.

I

Ian

Hello, I'm guessing this is straight forward and I'm just missing
something. I want to return a message to my JSP page when a query
search returns no matches. here is the start to my code:

<html>
<head>
<title>Search Results</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:eek:dbc:pHD","","");
String query = "SELECT * FROM Course_Details WHERE Subject_Area LIKE ?
OR Location Like ? ";
java.sql.PreparedStatement statement =
connection.prepareStatement(query);
statement.setString(1,request.getParameter("Subject_Area"));
statement.setString(2,request.getParameter("Location"));
//statement.setString(3,request.getParameter("UKCitizensonly"));
//statement.setString(4,request.getParameter("PreviousStudy"));
java.sql.ResultSet RS = statement.executeQuery();
%>
<body bgcolor="#99CCFF">

<%
if (query ==" ")
else
%>




<%
while(RS.next())
{



%>

I've tried putting in an if statment but don' no what I'm doing wrong

Thanks in advance for any help
 
E

Erwin Moller

Ian wrote:

Hi Ian,

I commented on some pieces...
Hello, I'm guessing this is straight forward and I'm just missing
something. I want to return a message to my JSP page when a query
search returns no matches. here is the start to my code:

<html>
<head>
<title>Search Results</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:eek:dbc:pHD","","");
String query = "SELECT * FROM Course_Details WHERE Subject_Area LIKE ?
OR Location Like ? ";
java.sql.PreparedStatement statement =
connection.prepareStatement(query);
statement.setString(1,request.getParameter("Subject_Area"));
statement.setString(2,request.getParameter("Location"));
//statement.setString(3,request.getParameter("UKCitizensonly"));
//statement.setString(4,request.getParameter("PreviousStudy"));
java.sql.ResultSet RS = statement.executeQuery();
%>
<body bgcolor="#99CCFF">

<%
if (query ==" ")

When will this happen?
In your above code query is always some prepared statement...
Take this out.
else
%>




<%
while(RS.next())
{

Am I missing something?
I was expecting you to do some operations on RS to get the data out.
Did you post all your code?
If this is all your code, that explains why you don't see a thing.
This cannot be compiled.

You open the while(RS.next()){

but don't close it and do nothing inbetween.

Please post all the relevant code if there is more.
 
I

Ian

Hello Erwin, here is my all my code that you were trying to help me
with yesterday. If I get the message working for no results then when
I try for results I know are there it is not returning any of my data.
It must have something to do with my the while statement.

Thanks for your help



Really appreciate it



Regards



Ian







<html>

<head>

<title>Search Results</title>

<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

</head>

<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:eek:dbc:pHD","","");

String query = "SELECT * FROM Course_Details WHERE Subject_Area LIKE ?
OR Location Like ? ";

java.sql.PreparedStatement statement =
connection.prepareStatement(query);

statement.setString(1,request.getParameter("Subject_Area"));

statement.setString(2,request.getParameter("Location"));

//statement.setString(3,request.getParameter("UKCitizensonly"));

//statement.setString(4,request.getParameter("PreviousStudy"));

java.sql.ResultSet RS = statement.executeQuery();

%>

<body bgcolor="#99CCFF">



<%

if (!RS.next()) {

out.println("No Results were found, please try again");

} else

// Output row data

while (RS.next());

{



%>















<table width="464" border="0" cellpadding="0" cellspacing="0"
bgcolor="#CCCCCC">

<!--DWLayoutTable-->

<tr>

<td width="14" height="21"></td>

<td width="46">&nbsp;</td>

<td width="1"></td>

<td width="21"></td>

<td width="31"></td>

<td width="6"></td>

<td width="7"></td>

<td width="20"></td>

<td width="12"></td>

<td width="19"></td>

<td width="14"></td>

<td width="27"></td>

<td width="23"></td>

<td width="5"></td>

<td width="12"></td>

<td width="9"></td>

<td width="19"></td>

<td width="44"></td>

<td width="10"></td>

<td width="27"></td>

<td width="1"></td>

<td width="49"></td>

<td width="33"></td>

<td width="14"></td>

</tr>

<tr>

<td height="20"></td>

<td colspan="4" valign="top"><font color="#0000FF"
size="4">Subject Area</font></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td height="7"></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td height="122"></td>

<td colspan="22" valign="top"><%=RS.getString("Subject_Area")
%></td>

<td>&nbsp;</td>

</tr>

<tr>

<td height="19"></td>

<td></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td height="20"></td>

<td colspan="3" valign="top"><font color="#0000FF"
size="4">Location</font></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td height="6"></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td height="23"></td>

<td colspan="14" valign="top"><%=RS.getString("Location") %></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td height="14"></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td height="20"></td>

<td colspan="7" valign="top"><font color="#0000FF"
size="4">Funding Available</font></td>

<td>&nbsp;</td>

<td>&nbsp;</td>



</tr>

<tr>

<td height="7"></td>



</tr>

<tr>

<td height="18"></td>

<td colspan="18" valign="top"><%=RS.getString("Stipend") %></td>



</tr>

<tr>

<td height="8"></td>



</tr>

<tr>

<td height="20"></td>

<td colspan="4" valign="top"><font color="#0000FF"
size="4">Starting Date</font></td>



<td colspan="7" valign="top"><font color="#0000FF" size="4">Course
Duration</font></td>



</tr>

<tr>

<td height="8"></td>



</tr>

<tr>

<td height="21"></td>

<td valign="top"><%=RS.getString("Starting_month") %></td>

<td>&nbsp;</td>

<td colspan="3" valign="top"><%=RS.getString("Year") %></td>

<td>&nbsp;</td>

<td>&nbsp;</td>



<td>&nbsp;</td>

<td>&nbsp;</td>

<td colspan="7" valign="top"><%=RS.getString("CourseDuration")
%></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td></td>

</tr>

<tr>

<td height="19"></td>

<td>&nbsp;</td>





</tr>

<tr>

<td height="2"></td>

<td colspan="9" rowspan="3" valign="top"><font color="#0000FF"
size="4">Number

of Vacancies</font></td>



</tr>

<tr>

<td height="18"></td>

<td></td>

<td colspan="6" valign="top"><%=RS.getString("NumberofVacancies")
%></td>



</tr>

<tr>

<td height="1"></td>



</tr>

<tr>

<td height="13"></td>





</tr>

<tr>

<td height="20"></td>

<td colspan="7" valign="top"><font color="#0000FF" size="4">UK
Citizens only</font></td>

<td>&nbsp;</td>

<td colspan="7" valign="top"><%=RS.getString("UKCitizensonly")
%></td>

<td>&nbsp;</td>



</tr>

<tr>

<td height="15"></td>



</tr>

<tr>

<td height="20"></td>

<td colspan="12" valign="top"><font color="#0000FF"
size="4">Previous Post-Graduate

Study</font></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td colspan="5" valign="top"><%=RS.getString("PreviousStudy")
%></td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td></td>

</tr>

<tr>

<td height="15"></td>





</tr>

<tr>

<td height="20"></td>

<td colspan="4" valign="top"><font color="#0000FF"
size="4">Website Link</font></td>

<td></td>

<td></td>

<td colspan="11" rowspan="2"
valign="top"><%=RS.getString("Website") %></td>



</tr>

<tr>

<td height="3"></td>



</tr>

<tr>

<td height="26"></td>

<td>&nbsp;</td>



</tr>

<tr>

<td height="42"></td>

<td colspan="18" valign="top">



</td>



</tr>

<tr>

<td height="21"></td>

<td colspan="21" valign="top"><hr align="center"></td>

<td>&nbsp;</td>

<td></td>

</tr>

<tr>

<td height="68"></td>

<td>&nbsp;</td>



</tr>









<%

}

RS.close();

connection.close();

%>

</table>



</body>

</html>
 
E

Erwin Moller

Ian said:
Hello Erwin, here is my all my code that you were trying to help me
with yesterday. If I get the message working for no results then when
I try for results I know are there it is not returning any of my data.
It must have something to do with my the while statement.

<snip>

Hi Ian,

I think this is your mistake, look at the following piece of code:


int i = 0;
while (i<10);{
System.out.println("i="+i);
i++;
}

This code is like your whileloop.
Do you expect this code to print:
i=0
i=1
i=2
etc etc ???

But it doesn't print a thing!
Why?
Because you made a typo.

you state: while(expression); {
// this is NEVER reached from the whileloop!!
}

Look at the ;

That means END OF BLOCKCODE {} in this context!

So remove the ; and you'll be fine.

It should be:
while (expression) {
// your code IN the whileloop

}


Good luck.
Regards,
Erwin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top