tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boon K. Chee" <brandon_c...@imedia-tech.com>
Subject Re: problem with mysql and tomcat
Date Wed, 24 Apr 2002 16:49:27 GMT
Dear Manny,

      I'm not an expert in mysql, but I did manage to run my apache2, tomcat
4 and mysql without any problem. I think the problem you have might not be
the mm.mysql driver problem. It seems to me that either your sql
statement(when you open the connection to mysql) is not quite right because
the mysql server has denied your access to the database. Make sure you put
your sql statement correctly when you open a connection. Below is the sample
code I use to connect to mysql:

  String connectionURL = "jdbc:mysql://servername/database_name";
  Connection connection = null;
  Statement statement = null;
  ResultSet resultSet = null;
  try
  {
   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
   connection = DriverManager.getConnection(connectionURL, "username", 
password");
   statement = connection.createStatement();
   resultSet = statement.executeQuery("SELECT Name, Username FROM tblUsers "
+
            "ORDER BY Name");
   while (resultSet.next()){
    out.println("<tr><td>" + resultSet.getString("Name") + "</td><td>"
       + resultSet.getString("Username") + "</td></tr>");
   }
   if (resultSet != null){
    resultSet.close();
   }
  } catch (ClassNotFoundException e){
   System.err.println("Couldn't find the mm " + "database driver: " + e
getMessage());
  } catch (InstantiationException e) {
   System.err.println(e.getMessage());
  } catch (IllegalAccessException e) {
   System.err.println(e.getMessage());
  } catch (SQLException e) {
   System.err.println("SQL Problem : " + e.getMessage());
   System.err.println("SQL State   : " + e.getSQLState());
   System.err.println("Vendor Error: " + e.getErrorCode());
  }

    Just substitute those servername, database_name, username and password
with your own. Hope this help. bye.

Cheer,
Brandon
-------Original Message-------

From: Tomcat Users List
Date: Tuesday, April 23, 2002 01:38:04 AM
To: tomcat-user@jakarta.apache.org
Subject: problem with mysql and tomcat

hi i've downloaded the mysql and loaded the driver(mm.nysql) driver for it
If i try to use it in a regular program without involving the server(tomcat3
2.1) it works fine . i can get the resultset etc which is fine. But when i
created another applicatoin which involved the use of Tomcat it gives me
error saying 

Started: 21:13:29.210 PM
Error: java.sql.SQLException: Invalid authorization specification: Access
denied for user: 'username@localhost' (Using password: YES) 

i've looked at hundreds of webpages but nothing so far has revealed a
suitable reaason and solution for it. one webpage said to put the jar file
in WEB-INF/lib dir but in my version of tomcat3.2.1 theres no subdirectory
as that . if anyone knows the solution to it please let me know.my email
address is 
mannychohan@hotmail.com
thanks
manny 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message