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.

It seems like you have some other "Statement" class included in your Servlet as opposed to the "java.sql.Statement". This is pretty easy to decipher as your compiler has clearly stated:-

java: 95 : cannot find symbol
symbol : method close()
location : class java.beans.Statement
stmt.close();

Check your imports and in case you have some other custom class/interface/Enum etc called as "Statement" already imported then I suggest you use "java.sql.Statement" whenever you wish to perform some SQL stuff.

Also a suggestion to help you in debugging, In the rush to find a solution do not forget to first understand the problem i. e. just ponder over and try to understand the error messages before looking for a solution.

BTW please use code tags whenever posting code. It is as simple as putting
[code=java] and [/code] around your code. It has many advantages like preserving indentations, providing syntax highlighting and also makes it easy to copy paste the code in case we want to test it at our end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.