0

i wanted to connect for mysql database, while installing mysql i not gave any password, so in my program i did the same but i am getting error on connection. I am using properties file to get driver,url,username and password help me pleas.

this is my code,

try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/easylibdb1","root","");

        } 
        catch (Exception e) 
        {
            System.out.println("Got Error While Connecting To Database...!");
            e.printStackTrace();
        }

this is my properties file content,

driver=com.mysql.jdbc.Driver

url=jdbc:mysql://192.168.1.51:3306/easylibdb1

user=root

password=""

and stack trace is as fallow..

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at com.easylib.AccessionFormat.mySqlConnection(AccessionFormat.java:111)
    at com.easylib.Index.main(Index.java:12)
Sanjaya Liyanage
  • 4,706
  • 9
  • 36
  • 50
Rajesh Hatwar
  • 1,843
  • 6
  • 39
  • 58

2 Answers2

0

This is a duplicate of: Mysql Connection with out password using corejava program

And you're still using the double quotes as password.

You should replace password="" with password=

and/or

replace con=DriverManager.getConnection("jdbc:mysql://localhost:3306/easylibdb1","root",""); with con=DriverManager.getConnection("jdbc:mysql://localhost:3306/easylibdb1","root",null);

Community
  • 1
  • 1
JREN
  • 3,572
  • 3
  • 27
  • 45
  • that's ok, i am geting like this error: java.sql.SQLException: Access denied for user 'root'@'192.168.1.37' (using password: NO) – Rajesh Hatwar Jun 20 '13 at 09:11
0

I think the root user don't have permissions to access the database. so you need to give the access by grant option in mysql. Execute the following in your mysql command line.

GRANT ALL ON easylibdb1.* TO 'root'@'%'; 

I hope it will work.

Prabhakar Manthena
  • 2,223
  • 3
  • 16
  • 30