Results 1 to 4 of 4
- 03-29-2009, 09:33 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
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.
- 04-02-2009, 09:22 PM #2
No need to cast. It gives then the error, and Statement then cannot be closed, cuz had never been openedJava Code:Statement stmt = con.createStatement();
- 04-04-2009, 05:45 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
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?!
- 04-04-2009, 08:37 AM #4
Similar Threads
-
How to use JDBC Template classes to control basic JDBC processing and error handling
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 10:17 AM -
Using JDBC-ODBC bridge
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:21 AM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM -
Security Violation:attempt to use Restricted Class: sun.jdbc.odbc.JdbcOdbcDriver
By Heather in forum Advanced JavaReplies: 1Last Post: 07-14-2007, 05:59 PM -
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
By Marcus in forum JDBCReplies: 1Last Post: 06-27-2007, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks