Results 1 to 5 of 5
  1. #1
    gb.rashu is offline Member
    Join Date
    Aug 2010
    Posts
    28
    Rep Power
    0

    Question URL problem in mysql connection in jsp

    Hello All,
    I am writing code for mysql connection using IP address with JSP. It is not connecting to mysql. can any one tell me solution for this:-(

    Thanks in advance
    Rashmi

    below is the jsp file


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page language="java" import="java.sql.*;" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <% Connection con = null;
    ResultSet rs = null;
    Statement st = null;
    try {
    String dbuser = "root";
    String dbpass = "admin";
    String url = "jdbc:mysql://192.168.0.13/mysql";

    Class.forName("com.mysql.jdbc.Driver").newInstance ();

    con = DriverManager.getConnection(url, dbuser, dbpass);

    st = con.createStatement();
    out.println("database connection esablished");


    }

    catch(SQLException e)
    {
    out.println("can not connect to database");

    }
    finally
    {



    }
    %>
    </body>
    </html>

  2. #2
    go4soumya is offline Member
    Join Date
    Oct 2010
    Posts
    32
    Rep Power
    0

    Default paste error code

    remove "out.println("can not connect to database");" line from the catch block and instead write: "out.print(e.getMessage());" ......run it and paste the error message. There may be a lot of reasons for not being able to connect to database..!!...Error message is important!

  3. #3
    gb.rashu is offline Member
    Join Date
    Aug 2010
    Posts
    28
    Rep Power
    0

    Default

    Hello soumya,
    Thanks for the quick reply,

    the error message is like :

    null, message from server: "Host '192.168.0.23' is not allowed to connect to this MySQL server"

    Thanks in advance
    Rashmi

  4. #4
    go4soumya is offline Member
    Join Date
    Oct 2010
    Posts
    32
    Rep Power
    0

    Default Expected solution

    In your first post your url was ---
    String url = "jdbc:mysql://192.168.0.13/mysql";--
    But the error msg says: "192.168.0.23".... :confused:

    whatever it is....it seems u don't have the permission for accessing or logging in from this machine(s) other than localhost.

    Add 192.168.0.23(/13) as a user(or ask your db admin to do it), grant privileges, and hopefully it'll solve your problem!

    I don't use mysql, but i think the command goes like this:
    CREATE USER 'rashmi'@'192.168.0.23' IDENTIFIED BY 'yourPassword';

    and then:
    GRANT SELECT,INSERT,UPDATE,DELETE ON <database name>.* TO rashmi

    in case you get stuck, you may refer to: MySQL :: MySQL 5.1 Reference Manual :: 5.5.2 Adding User Accounts

    Hope this solves your problem...good luck!! :)

  5. #5
    gb.rashu is offline Member
    Join Date
    Aug 2010
    Posts
    28
    Rep Power
    0

    Default

    Hi soumya,
    it is executing successfully. . thank you for your suggestions.
    Thanks & Regards,
    Rashmi
    Last edited by gb.rashu; 11-19-2010 at 07:25 AM.

Similar Threads

  1. connection my mysql in jsp in myeclipse
    By pranjul137 in forum New To Java
    Replies: 12
    Last Post: 02-03-2014, 02:43 PM
  2. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
  3. TWO IPs FOR MY MYSQL CONNECTION
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 08:46 PM
  4. java mysql connection
    By sysout in forum New To Java
    Replies: 5
    Last Post: 10-31-2009, 10:48 AM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •