How to connect to a remote database with JDBC? - java

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?

Following on from duffymo, the string you want to use is jdbc:mysql://blablabla.rds.amazonaws.com/dbname?user=user&password=password as documented here

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.

Related

How can i connect Azure postgres database to pgadmin as im getting time out error

I have created a database in Azure database in postgreSQL but when i try connect through pgadmin it says unable to connect timeout expired(I'm pretty sure admin and password are correct). Is anyone facing this issue? is there an alternative for pgadmin ?
pgadmin works fine against Azure Postgres. A couple things to check:
Make sure you have a firewall exception in Azure for your local IP address.
Use the user#server format for your username
Use server.postgres.database.azure.comas your hostname
Make sure to set SSL Mode to require in the SSL tab
Good luck!
Below settings works for me, you can use below
pgadmin works perfectly against Azure database for Postgres. Here's the link to the docs.
Add your local IP to your firewall in Azure
In the Azure portal, navigate to connection strings to get your db credentials
Use the user#server format for your username
Use server.postgres.database.azure.com as your hostname
Maintenance database should be set to postgres
Ensure that SSL Mode is set to require under the SSL tab
That is what worked for me.
I got the timeout all of a sudden, and only after some time I realized it was the VPN that probably blocked a port or so. Once I disabled VPN it worked again. Just something to keep in mind.

Connecting to Heroku clearDB mySql

I'm dabbling with Heroku and managed to deploy a simple app. I added a ClearDB MySQL database instance that lives here:
mysql://[user]:[password]#us-cdbr-iron-east-04.cleardb.net
I'm trying to connect to it using "dbforge for mysql" but I'm not sure if this is possible. Anyone know if this would be possible? Below shows what the dbforge connection interface looks like as well as the error I get while trying to connect.
In the screenshot you show, the port is 1, which is incorrect. Check your DATABASE_URL to get the correct port or try 3306, which is the default MySQL port.
In addition, you may need to download and configure the SSL certificates.

Java, MySql -- connecting from another computer

I created a java program that uses MySql. Now I want to give the app to someone else, and I'm using the URL as: jdbc:mysql://ipAddress:3306/tableName, but it doesn't work, showing the error of connection failure.
What should I do?
It's a troubleshooting stuff, do the following.
Check the Firewall and Port access on MySQL Server computer.
Check the MySQL Service and the DB User is doing good.
Follow the following thread
How to allow remote connection to mysql

Unable to Access and Connect to MySQL Server Data Base

I am totally new to MySQL Server but good at Java! I know how to connect with the MySQL Server using Java. Recently, I have made a simple small MySQL Server (Test) app for me. Its just for my knowledge! I have successfully connected to the database and successful to use INSERT and SELECT Statements in my Java App.
The problem is that my app is only running on my that laptop on which the SQL Server 2008R2 is installed on! I just checked my app on my another Laptop and it says the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP
connection to the host localhost, port 1433 has failed. Error:
"Connection refused: connect. Verify the connection properties.
Make sure that an instance of SQL Server is running on the host
and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall.
I have tried this link so far no Success an still I can't access my Data Base on my other machine!
msdn.microsoft.com/en-us/library/ms175043.aspx
From an answer i also tried my best!
stackoverflow.com/a/12430561/2496503
From this answer i have come to know that my SQL Server Network Configuration(32-bit) is not showing any details/options as mentioned in the above answer here is a snapshot attached herewith !
PLEASE TELL ME IF IT IS ORDINARY THING THAT IT IS NOT SHOWING ANY OPTIONS! ELSE MY SQL SERVER ISN'T INSTALLED CORRECTLY PLEASE HELP ME GIVE ME JUST HINTS I WILL BE THANKFUL TO YOU !
Perform these Steps for TCP/IP network Configuration upto step 6, ur problem will be solved.
[http://www.visual-paradigm.com/support/articles/solve-sql-server-connection-problem.jsp][1]

IO Error: The Network Adapter could not establish the connection

I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.

Categories