Results 1 to 4 of 4
  1. #1
    lordelf is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Question Help me this error in JDBC-ODBC connection

    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:Phone";
    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.

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    Java Code:
    Statement stmt = con.createStatement();
    No need to cast. It gives then the error, and Statement then cannot be closed, cuz had never been opened

  3. #3
    lordelf is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    thanks serjant, I reused this code rs = stmt.executeQuery(newSQL); in tutorials. But I got an error "cannot find symbol" in my project. I don't know why?!

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    Maybe your query is not correct, cna you post all the Stack Trace

Similar Threads

  1. Replies: 0
    Last Post: 04-01-2008, 10:17 AM
  2. Using JDBC-ODBC bridge
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:21 AM
  3. Replies: 0
    Last Post: 09-28-2007, 12:56 PM
  4. Replies: 1
    Last Post: 07-14-2007, 05:59 PM
  5. Replies: 1
    Last Post: 06-27-2007, 05:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •