I try to use JDBC-ODBC but some errors occur, and I don't know why.
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
boolean found= false;
PrintWriter out = response.getWriter();
out.println("<html><head><title>SearchAccount</title></head>");
out.println("<body><h1>Your result:</h1>");
out.println("<table border = 1 cellPadding = 1 cellSpacing = 1>");
String sodienthoai = request.getParameter("PhoneNumber");
//SQL
String newSQL = "SELECT * FROM Phone WHERE PhoneNumber = " + PhoneNumber;
String conStr = "JDBC:ODBC:kPhone";
Connection con;
Statement stmt;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(conStr, "", "");
stmt = (Statement) con.createStatement();
rs = stmt.executeQuery(newSQL);
out.println("<tr><th>index</th><th>Host</th><th>PhoneNumber</th><th>Address</th></tr>\n");
if(rs!=null)
{
for( int i = 1; rs.next(); )
{
out.println("<tr><td>" + i + "</td><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</td><td>"
+ rs.getString(3) + "</td></tr>\n");
found = true;
}
}
out.println("</table>");
if(found==false)
out.println("no found");
rs.close();
stmt.close();
con.close();
}catch(Exception e)
{
System.out.println("Error: " + e);
}
}
the errors are :
java: 77 : cannot find symbol
symbol : method executeQuery(java.lang.String)
location : class java.beans.Statement
rs = stmt.executeQuery(newSQL);
and
java: 95 : cannot find symbol
symbol : method close()
location : class java.beans.Statement
stmt.close();
Hope to show me why, thanks in advance.