#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Germany
    Posts
    0
    Rep Power
    0

    JSP cannot connect to MySQL Server


    Hi,
    I am trying to connect to a MYSQL Server (not localhost)
    and I'm able to connect via MySQL Gui, no problem.

    But when trying to connect via JSP code, I get the following error
    message

    java.sql.SQLException: Server configuration denies access to data source
    at org.gjt.mm.mysql.MysqlIO.init(Compiled Code)
    at org.gjt.mm.mysql.Connection.connectionInit(Compiled Code)
    at org.gjt.mm.mysql.jdbc1.Connection.connectionInit(Compiled Code)
    at org.gjt.mm.mysql.Driver.connect(Compiled Code)
    at java.sql.DriverManager.getConnection(Compiled Code)
    at java.sql.DriverManager.getConnection(Compiled Code)

    I'm using this code...

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

    conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user + "&password=" +pass;

    Connection Conn = DriverManager.getConnection(conn);


    Could the problem be JDBC related? I would be very glad if
    someone could help. Thanx in advance

    otsche
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    1
    Rep Power
    0
    Just a possibility, have you edited your mySQL host tables to allow access from an outside source(not localhost)?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    10
    Rep Power
    0
    I am getting exactly the same error and don't know how to fix it, so if you have since rectified it can you post up here??
    Thanks
    Winston
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Germany
    Posts
    0
    Rep Power
    0
    Ok, guys thanks for your help.

    it was just as jim_dewit said,

    the problem was that jdbc/mysql connection (mm.mysql)
    was not properly configured. suprisingly, in the connection string
    in the jsp file
    i also had to use "localhost" as the host and not the ip address of the mysql - server.

    a sample of the code that works...
    // database parameters for all .jsp pages
    String host="localhost";
    String user="test";
    String pass="";
    String db="test";
    String conn;

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

    conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user + "&password=" +
    pass;
    Connection Conn = DriverManager.getConnection(conn);

    Statement SQLStatement2 = Conn.createStatement();
    String Query = "SELECT username,password FROM user WHERE username='"+username+"' AND password='"+password+"'";
    ResultSet SQLResult2 = SQLStatement2.executeQuery(Query);

    while (SQLResult2.next())
    {
    saved_pass = SQLResult2.getString("password");
    saved_user = SQLResult2.getString("username");

    }


    SQLResult2.close(); SQLStatement2.close();
    Conn.close();


    thx for your help
    so far
    otsche

IMN logo majestic logo threadwatch logo seochat tools logo