?
Solved

java sql access question

Posted on 2003-03-10
8
Medium Priority
?
223 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
7 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

621 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