Hello! All:
I get a problem to access mysql database from servlet program. I
am using JDBC to access the mysql. I have a servlet class to call the
function in another java class which connects the mysql database. From
the error message, the program has successfully load the driver and get
connected with the mysql since it prints the message up to "3:Hello".
The exception comes from the statement "ResultSet rs =
stmt.executeQuery(createString);". Could you tell me how to get arround
of this? Thank you!
The output on browser is "
1: Hello 2: Hello 3: Hello Result set exception E0610 Error in
executeQuery() E0606 executeQuery() error -- E0701 Error in getResult().
E0708 Command results in error - 1044 Access denied for user:
'@localhost' to database 'mysql'
"
The function to connect mysql is:
"public void getProductInfo(String name, PrintWriter out) {
String tableName;
String JDBCDriver = "twz1.jdbc.mysql.jdbcMysqlDriver";
Connection con;
String createString;
createString = "select * from Product where productName =
\"DVD\" ";
Statement stmt;
try {
Class.forName(JDBCDriver);
out.println("1: Hello");
} catch (Exception e) {
System.err.println("Unable to load driver.");
e.printStackTrace();
}
try {
con = DriverManager.getConnection( "jdbc:z1MySQL:");
out.println("2: Hello");
stmt = con.createStatement();
out.println("3: Hello");
try {
ResultSet rs = stmt.executeQuery(createString);
out.println("4: Hello");
while(rs.next())
{
MID = rs.getString(1);
PID = rs.getString(2);
productName = rs.getString(3);
description = rs.getString(4);
unitPrice = rs.getString(5);
out.println(description);
}
rs.close();
}catch (Exception et){
out.println("Result set exception"+ et.getMessage());
}
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
"
PS: This code works when it is called by local java classes.
Thanks a lot!!!
Sincerely:
Zheng Xi
-----------------------------------------------------
Zheng Xi [EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html