LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-08-2003, 02:57 PM   #1
juby
Member
 
Registered: Dec 2002
Location: Bangalore, India
Distribution: Ubuntu 5.*
Posts: 241

Rep: Reputation: 30
Unhappy My sql - Jdbc Access denied for user:


// To test jdbc in mysql

import java.io.*;
import java.sql.*;

public class dbTest
{
private Connection con;
private Statement stmt;
private ResultSet rs;
private String qry ="Select * from userData";

public static void main(String args[])
{
dbTest d = new dbTest();
}

public dbTest()
{
//String userName="juby@localhost.localdomain";
//String pwd="asdf";
//userName=userName.trim();
//pwd = pwd.trim();


try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//con=DriverManager.getConnection("jdbc:mysql://localhost/myDb;"+"uid="+userName+";pw="+pwd);
//con=DriverManager.getConnection
("jdbc:mysql://localhost/myDb;uid=juby@localhost;pw=asdf");

con=DriverManager.getConnection
("jdbc:mysql://localhost/myDb?user=juby&password=asdf");

}

catch(Exception e)
{
System.out.println("Driver/sql error" +e);
System.exit(1);
}



try
{

stmt = con.createStatement();
rs = stmt.executeQuery(qry);

while(rs.next())
{

System.out.println(rs.getString(1));
}

con.close();

}

catch(Exception e1)
{

System.out.println(e1);
}

}

} //class ends

/*

[juby: misc]-> javac dbTest.java
[juby: misc]-> java dbTest
Driver/sql errorjava.sql.SQLException: Invalid authorization specification: Access denied for user: 'juby@localhost.localdomain' (Using password: YES)

*/


can ne one geuss wht the problem is ? i can logon using the command @ shell

mysql -u juby -p
asdf

if i use root @ user in java code and remove the passwd field all works fine :'( plz help

i have all permissions for juby

grant all on *.* to juby


i have tried out various combination s & permutations for getConnection....which can be seen in th ecode
 
Old 05-08-2003, 03:28 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Try using:
Code:
GRANT ALL PRIVILEGES ON database.* TO juby@localhost IDENTIFIED BY "your_password";
Obviously change database to the name of your database and your_password to your password (keep the quotes though)
 
Old 05-08-2003, 06:51 PM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416
Maybe something like this:

Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager("jdbc:mysql://localhost/mydb","juby","pwd");

I've seen conflicting advice on whether you need the .newInstance() and I've successfully not used it. I also think you need to split the DriverManager values into separate strings.
 
Old 05-09-2003, 01:31 PM   #4
juby
Member
 
Registered: Dec 2002
Location: Bangalore, India
Distribution: Ubuntu 5.*
Posts: 241

Original Poster
Rep: Reputation: 30
i gave grant permission to juby@localhost.localdomain
& then used mysqladmin -u root flush-privileges to get it work !

the new code is

connStr = new String("jdbc:mysql://localhost/myDb?user="+userName+"&password="+pwd);
System.out.println(connStr);
Class.forName("org.gjt.mm.mysql.Driver");

//any of these will work, but i remember reading that the first apporach
// prevents sql injection for hacking ..not very sure abt it

//con=DriverManager.getConnection("jdbc:mysql://localhost/myDb?user=juby&password=asdf");
//con=DriverManager.getConnection("jdbc:mysql://localhost/myDb?user="+userName+"&password="+pwd);
//con=DriverManager.getConnection(connStr);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User Access Denied dhUmra Linux - General 1 06-06-2005 06:57 PM
MySQL: 'access denied for user' turbo_acura Linux - General 1 10-20-2004 09:34 AM
mySQL Access denied for user Gerardoj Linux - General 2 03-21-2004 11:13 AM
getting access denied , when trying to access camera as normal user bennythepitbull Linux - Hardware 2 11-04-2003 03:30 AM
MYSQL access denied for user c0c0deuz Linux - General 1 03-18-2003 03:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration