?
Solved

java sql access question

Posted on 2003-03-10
8
Medium Priority
?
213 Views
Last Modified: 2010-03-31
I keep getting the following error when trying to connect to my linux mysql server:
java.sql.sqlexception: server configuration denies access to data source

My code looks like this:
try {
             // Load the JDBC driver
             String driverName = "org.gjt.mm.mysql.Driver";
             String serverName = "localhost";
             String portNumber = "3306";
             String mydatabase = serverName + ":" + portNumber;
             String url = "jdbc:mysql://" + mydatabase + "/database01"; // a JDBC url
             String username = "root";
             String password = "12345678";
             
              Class.forName(driverName).newInstance();
              connection = DriverManager.getConnection(url, username, password);
              System.out.println("Driver loaded");
         } catch (ClassNotFoundException e) {
             System.out.println("Could not find the driver");
         } catch(java.lang.InstantiationException e) {
              System.out.println("Connection Error");
         }catch (SQLException e) {
             System.out.println(e + "\nCould not connect to the database");
         }catch (Exception e) {}

Where am I going wrong here?  the root password for the mysql server is 12346578, so why wont it let me connect?
0
Comment
Question by:lwinkenb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8101453
we are using folloing to get connection with MySQL and it works correctly, even ur is perfact, pls try this

conection = DriverManager.getConnection("jdbc:mysql://localhost:3306/database01?user=root&password=12345678");
0
 

Expert Comment

by:vfwood
ID: 8102106
hi

have a look here:

http://dbforums.com/arch/92/2002/7/426064

hope this helps.
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 8104796
vfwood >> I have already visited that thread with no luck.

umangjoshi >> Tried your suggestion, but it didnt work.
0
Independent Software Vendors: 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!

 
LVL 1

Expert Comment

by:jcaldwel
ID: 8105930
Are you getting an exception? What is the stack trace?
0
 
LVL 5

Accepted Solution

by:
lwinkenb earned 0 total points
ID: 8109926
I found my problem.  For those interested, this is what I had to do to fix it.

I had set permissions in mysql using:
GRANT ALL PRIVILEGES ON *.* TO username@localhost
    IDENTIFIED BY 'password' WITH GRANT OPTION;

but what I also need to run was:
GRANT ALL PRIVILEGES ON *.* TO username@%
    IDENTIFIED BY 'password' WITH GRANT OPTION;

0
 

Expert Comment

by:CleanupPing
ID: 9058824
lwinkenb:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Expert Comment

by:medions
ID: 10922959
The answer on this question was that you'll have to create 2 users, one with localhost and one with % as host! <- don't ask me why :)

Who want points?

Rune
0

Featured Post

Technology Partners: 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

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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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