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)
3
  • con=DriverManager.getConnection("jdbc:mysql://localhost:3306 easylibdb1","root",null); Commented Jun 20, 2013 at 8:38
  • If on Unix than try in Terminal mysql -u root if it connects Commented Jun 20, 2013 at 8:38
  • that's ok, i am geting like this error: java.sql.SQLException: Access denied for user 'root'@'192.168.1.37' (using password: NO) Commented Jun 20, 2013 at 9:14

2 Answers 2

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);

Sign up to request clarification or add additional context in comments.

1 Comment

that's ok, i am geting like this error: java.sql.SQLException: Access denied for user 'root'@'192.168.1.37' (using password: NO)
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.