Java and MySQL: Could not create connection to database server
Posted by: cronodragon (---.cable.net.co)
Date: January 27, 2012 07:00PM

I need urgent help on this, please!

I'm trying to connect a program in Java with the MySQL installed with WAMPSERVER v2.2. I'm connecting to:

jdbc:mysql://localhost/configuracion_servidor:3306?autoReconnect=true

My user is "root", no password as default. testmysql.php works fine. But in Java I get this error (copy-pasted from console):

Could not create connection to database server. Attempted reconnect 3
times. Giving up.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not
create connection to database server. Attempted reconnect 3 times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:
2226)
...

Am I missing something in "my.ini"?

I found this: [bugs.mysql.com] . It says one should add "mysqld : ALL : ACCEPT" to /etc/hosts.allow... how do you do that in WAMP? Does it help anyway?

Please help me here smiling smiley Thanks in advance!

Options: ReplyQuote
Re: Java and MySQL: Could not create connection to database server
Posted by: infopeer (220.224.230.---)
Date: January 30, 2012 09:17AM

cronodragon ,

Create another user & execute the below queries on your mysql server in the specified order.

GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'192.168.1.0/255.255.255.0';


FLUSH PRIVILEGES;

exit



Where 192.168.1.0/255.255.255.0 should be your specific subnet.

Let me know if the issue is resolved.

Thanks,

Founder & Administrator
[www.infopeer.com]
[www.zaadu.com]

Options: ReplyQuote
Re: Java and MySQL: Could not create connection to database server
Posted by: cronodragon (---.cable.net.co)
Date: January 30, 2012 01:46PM

Thank you for your help infopeer. Unfortunately didn't work, here are the screenshots of the result:

[gamelix.com]
[gamelix.com]

I also tried adding 192.168.0.12 but didn't work neither. Is there something else I could do?

Thank you again and regards!
-Marco

Options: ReplyQuote
Re: Java and MySQL: Could not create connection to database server
Posted by: cronodragon (---.cable.net.co)
Date: January 30, 2012 02:41PM

Ahhh I was using a wrong URL to connect:

jdbc:mysql://localhost/configuracion_servidor:3306?autoReconnect=true

The port is in the wrong position, instead it should be:

jdbc:mysql://localhost:3306/configuracion_servidor?autoReconnect=true

Thank you anyway! I learned some new things. grinning smiley

-Marco

Options: ReplyQuote


Sorry, only registered users may post in this forum.