Mysql Connection with out password using corejava program

后端 未结 8 1302
你的背包
你的背包 2020-12-07 03:21

I want to connect to a MySQL database. While installing MySQL I did not give any password, so in my program I did the same but I am getting error on connection. I am using p

相关标签:
8条回答
  • 2020-12-07 03:35

    The password argument should be set to null because even an empty String "" implies that there is a password.

    DriverManager.getConnection("jdbc:mysql://localhost:3306/easylibdb1","root",null)
    
    0 讨论(0)
  • 2020-12-07 03:40

    using password: NO - this means the program is not passing any password, in your case that is correct.

    Since you mention that you are reading the values from the properties file, I don't see you doing that in the code you have posted. If you are really reading the values from the properties file in your actual code, and the MySQL server is a remote server, then make sure that you grant relevant permissions on the remote MySQL server with the below statement

    grant all privileges on easylibdb1.* to 'root'@'192.168.1.51' to allow connections originating from 192.168.1.51

    or

    grant all privileges on easylibdb1.* to 'root'@'%' to allow connections originating from anywhere

    0 讨论(0)
  • 2020-12-07 03:45

    Pass null as password instead of an empty String. That should make it work.

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

    From what I see right now, you're actually not using the values from the properties file.

    0 讨论(0)
  • 2020-12-07 03:49

    According to you, you are passing username as root and password as empty string.And your connection is established through

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

    So change your function as

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

    Then it will work. Or change the password in the application.properties file as

    password=
    
    0 讨论(0)
  • 2020-12-07 03:56

    If it's really password="" what stands in your properties file, then "" will be sent as password. Not an empty string but the two quote signs.

    0 讨论(0)
  • 2020-12-07 03:58
    URL=jdbc\:mysql\://192.168.1.51:3306/easylibdb1
    USER=root
    PASSWD=
    DRIVER=com.mysql.jdbc.Driver
    

    Please set ur PASSWORD Field as blank.. Don't put quote.

    0 讨论(0)
提交回复
热议问题