File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Error in Hibernate url for mysql ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error in Hibernate url for mysql ?" Watch "Error in Hibernate url for mysql ?" New topic
Author

Error in Hibernate url for mysql ?

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi

I am using simple hibernate application with mysql.

I have database name 'prabhat' in mysql.


when i execute the hiberante client file i get error in console:

WARNING: Could not obtain connection metadata
java.sql.SQLException: Access denied for user 'admin'@'INDIC6HF92.in.atosorigin.com' (using password: YES)

so i changed the host name form localhost to IP address.

String url = "jdbc:mysql://192.168.1.100/prabhat";

but still i get the same error.

what is the problem could nay one give me pointer to fix it.

Regards,
Prabhat
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You don't have a sufficient permission to access the db, use GRANT query to have it.
MySQL GRANT: http://dev.mysql.com/doc/refman/5.1/en/grant.html
Example: http://www.java2s.com/Code/SQL/User-Permission/Verifythegrant.htm

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
april henry
Greenhorn

Joined: Jan 18, 2010
Posts: 9
I think your url is wrong.

String url = "jdbc:mysql://192.16.1.100:3306/prabhat";

but you must make sure your port is 3306,if not ,please change it.

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
Hi,

I have changed the URL also as per your suggestion.

<property name="connection.url">jdbc:mysql://localhost:3306/mysql</property>

But Still i getting error :

java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)

I have one user admin/admin

So i wrote in xml file

<property name="connection.username">admin</property>
<property name="connection.password">admin</property>

But i have database name mysql,test & prabhat.

what should i do and which database should i use and which user has access .

Regards,
prabhat
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
see this is the last error:

an 19, 2010 12:31:47 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/mysql
Jan 19, 2010 12:31:47 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=admin, password=****}
Jan 19, 2010 12:31:47 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:798)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3700)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1203)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at Test.main(Test.java:11)
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 391
I fixed the issue !

created the user and GRANT the privilages and laso updated all this info to hibernate.cfg.xml file

then evreything is working fine !

1) Create user ranjan identified by 'myself';

2) GRANT ALL ON prabhat.* TO 'ranjan';

3)
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/prabhat</property>
<property name="connection.username">ranjan</property>
<property name="connection.password">myself</property>

above is my changes.

 
jQuery in Action, 2nd edition
 
subject: Error in Hibernate url for mysql ?