tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Teiji Sawa <te...@itsa.ucsf.edu>
Subject JDBC and MySQL in Linux and MacOSX
Date Wed, 18 Jul 2001 01:26:30 GMT
Could you help me about JDBC for MySQL!

I instilled Tomcat4.0 and Cocoon2 in my Mac OS-X. It worked without trouble!
Next, I tried MySQL connection with JDBC driver (mm.mysql-2.0.4-bin-jar) and
it worked without trouble again in Mac OS X in which I installed MySQL with
PHP, too (Not surprising? But very exciting for me at least)!

Then I tried the same things in my Red-Hat linux (6.1) in which I was using
MySQL with PHP for our web-site without trouble.
However, this time, JDBC for MySQL never work in linux.

I was using the following Java program for checking connectivity to MySQL,
and it worked in Mac OS X, but not Linux, and I always get the following
message in Linux.  I think MySQL setting is OK, because PHP script is
successfully retrieving data from MySQL in the same access privilege.


It may be unusual, but for me, so far, Mac OS-X is much easier for me to run
"Tomcat, Cocoon2 and MySQL with JDBC" than Linux!



#java JDBCTest.java
java.sql.SQLException: Server configuration denies access to data source
    at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:193)
    at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:261)
    at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
    at org.gjt.mm.mysql.Driver.connect(Driver.java:167)
    at java.sql.DriverManager.getConnection(DriverManager.java:517)
    at java.sql.DriverManager.getConnection(DriverManager.java:199)
    at JDBCTest.main(JDBCTest.java:20)



PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/java/jdk1.3.1/bin:
JAVA_HOME=/usr/java/jdk1.3.1
TOMCAT_HOME=/usr/java/jakarta-tomcat-4.0
CLASSPATH=:/usr/java/j2sdkee1.2.1/lib/j2ee.jar:/usr/java/jdk1.3.1/lib/tools.
jar:/usr/java/mm.mysql/mm.mysql-2.0.4-bin.jar:/usr/java/jakarta-tomcat-4.0/w
ebapps/sect8/WEB-INF/classes/com:/usr/java/lib:/usr/java/jsdk2.1/servlet.jar
ANT_HOME=/usr/java/jakarta-ant-1.3
JAXP_HOME=/usr/java/jakarta-tomcat-4.0/server/lib


#cat JDBCTest.java 
import java.sql.*;
import java.lang.*;
import java.io.*;
import java.util.*;

public class JDBCTest {
  public static void main(String argv[]) {
    Connection con = null;

    String hostname = "localhost";
  String username = "root";
    String password = "xxxxxx";

  try {
      Statement stmt;
      ResultSet rs;

      Class.forName("org.gjt.mm.mysql.Driver");

    con = DriverManager.getConnection("jdbc:mysql://"
          + hostname
          + "/mysql?user="
          + username
          + "&password="
          + password);
    }
    catch (Exception e) {
      e.printStackTrace();
    }

    if (con == null) {
      return;
    }

    try {
      Statement Stmt = con.createStatement();

      ResultSet RS = Stmt.executeQuery("SELECT User, Host from user;");

      while (RS.next()) {
        String user = RS.getString("User");
        String host = RS.getString("Host");
        System.out.println(user + ":" + host);
      }

      con.close();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}




Mime
View raw message