Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How Do I resolve "cannot resolve" issue in java?

843840Mar 8 2008 — edited Mar 8 2008
I am new to java so forgive me if the following question sounds a bit too simplistic.
I am trying to write a servelet that queries and returns data from a database. My code for quering the data
works fine in java using the main method. However when i am trying to put that in a servlet I get
the message "variable name (results) cannot be resolved.) I have declared it and the type is correct.
I am hitting a brick wall and not sure how to resolve it. Code is as shown below....

package simpletest;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;


public class SearchProperty extends HttpServlet{
private static Connection conn;

void doPost(HttpServletResponse response, HttpServletRequest request)
throws IOException, ServletException, NumberFormatException, SQLException {

/**
*This class does the property search based on the user input from
*search.html. It queries an Oracle Database that has the information stored
*for each property.
*
*/

try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
}
catch(SQLException sqlEx)
{
System.out.println("*** Unable to load driver***");
System.exit(1);
}

try
{
conn = DriverManager.getConnection("jdbc:oracle:thin:@home-pc:1521:XE", "system", "addis0906");
}catch(SQLException sqlEx)
{
System.out.println("Cannot connect to database");
System.exit(1);
}

try{
Statement statement=conn.createStatement();
String selectAll="SELECT * from property_data order by price desc";
ResultSet results=statement.executeQuery(selectAll);
}
catch(SQLException sqlEx)
{
System.out.println("Cannot Execute Query");
sqlEx.printStackTrace();
System.exit(1);
}
int count=0;


System.out.println("<HTML><TITLE>Propert Search Result</TITLE><BODY>");
System.out.println("<BODY BGCOLOR='white'>");
System.out.println("<TABLE BORDER='0' WIDTH=\"600\" BGCOLOR=#7b9cbd><TR><b>myProperty Search<b></TR>");
System.out.println("<TABLE BORDER=2 WIDTH=\"600\" CELLPADDING='1' BGCOLOR=#f7f7e7>");

System.out.print("<CAPTION ALIGN='left'><p font-color='blue'><span style='font-size:12.0pt;font-family:Courier;color:#336699'>");
System.out.println("This is the result of your search<span></p></CAPTION>");

while (results.next()) {
int bed_nums;
double prop_price;
count++;
if (results.getString(3).equals("Any"))
bed_nums=20;
else
bed_nums=Integer.parseInt(results.getString(3));

if (results.getString(2).equals("Any"))
prop_price=2000000000;
else {
prop_price=Double.parseDouble(results.getString(2));
if (prop_price >2000000000){
System.out.println("This programme does not accept property price of more than 200 million");

}
}


String address=results.getString(4);
displayHTML(results.getString(1), bed_nums, prop_price,address,count);
}

conn.close();
System.out.println("</TABLE>");
System.out.println("<TABLE BORDER='1' WIDTH='600' BGCOLOR=#7b9cbd><TR>&nbsp</TR>");
System.out.println("</BODY></HTML>");

}
private static void displayHTML(String location, int num_beds, double price, String address, int count ) {

System.out.println("<TR id=\"row" + count + "\"</TR>");
System.out.println("<TH align='left'> " + address + ",<br>" + location + "<TD>" + num_beds + " beds\t<TD> " + "EUR " + price);



}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2008
Added on Mar 8 2008
3 comments
276 views