简体   繁体   中英

How to connect to a remote database with JDBC?

I'm trying to connect to a remote database via JDBC. Here's my connection string:

db=mysql://user:password@blablabla.rds.amazonaws.com/dbname

At a first glance it seems like it should work, but on trying it, I get the error:

Cannot connected to the database, An attempt by a client to checkout a Connection has timed out.

I'm trying to use Play framework (1.2.x) and have described this db connection in the conf file.

Any ideas?

Yes, this is the wrong URL.

You need the MySQL Connector-J JDBC driver JAR in your CLASSPATH.

The URL should look like this:

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

I would recommend not putting the credentials in the URL. Add them in Java.

If you're getting an error, please post the stack trace. That will help to diagnose what you did wrong.

Can you connect to that database using the MySQL admin tool? Can you ping that server? Can you telnet to that port? If not, Java won't connect, either. Is there a firewall between your client machine and the database server? If yes, then the MySQL port has to be open for you.

在duffymo之后,您要使用的字符串是jdbc:mysql://blablabla.rds.amazonaws.com/dbname?user=user&password=password ,如此处所述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM