Solved

Java MySQL connection

Posted on 2004-08-14
3
231 Views
Last Modified: 2010-03-31
I am trying to connect java application with mysql.
Earlier mysql was installed on a remote machine and the connection was working fine. But now i was testing it by installing it on the local machine. So changed the host name from name of server to localhost and specified user name and password for local mysql database.
But now i can't conenct to the local databse.
i am getting the following Error

Access denied to user abc@127.0.0.1 (Using password:YES).

But i can directly run the database from prompt.

Please Help
0
Comment
Question by:thomas908
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 11799133
Check exactly who you have granted login to and that abc@127.0.0.1 is one of them

http://dev.mysql.com/doc/mysql/en/GRANT.html
0
 
LVL 8

Author Comment

by:thomas908
ID: 11799151
i logged on to mysql database and did

 GRANT ALL ON *.* to abc;

and got the follwoign error
ERROR 1045: Access denied for user: '@127.0.0.1' (Using password: NO)
0
 
LVL 6

Assisted Solution

by:manuel_m
manuel_m earned 250 total points
ID: 11799278
can you connect as root ?

can you post your code?

look here: http://homepage.mac.com/murraytodd/enterprise/mysql.html
maybe it can help you

i test this and it works fine on my localhost mysql: (using newest mysql driver 3.0.14)

  private static final String DB_URL = "jdbc:mysql://localhost/maq?user=root&password=password";

  private static Connection conn = null;

  public SQLConnectionTest() {

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/dbName?user=root&password=password";);
      if (!conn.isClosed()) {
        System.out.println("closing connection...");
      }
    } catch (Exception ex) {
      System.out.println("Connection failed: "+ ex.getMessage());
      ex.printStackTrace();
    }
  }
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question