Reputation: 1622
I have always used a database
located in my pc, so the steps to connect to it are:
jdbc
now, i want to know what are the steps if the database
is located in an online server
?
some guides,tutorials are very appreciated.
Upvotes: 0
Views: 1527
Reputation: 1000
Since you will be connecting to a remote database I would advise you to read about secure connections using JDBC. See this question, for example. You don't want to interact with a remote database without something like SSL to protect the confidentiality of the data.
Once you think you have secured your connection, you can use a tool like Wireshark to make sure that the packets that are going to and coming from your database are in fact opaque.
Furthermore, as others have said, not much changes if you already have a working connection to a local database, it's a matter of changing your URL from jdbc:mysql://localhost:port/database
to jdbc:mysql://ipaddress:port/database
.
From my experience, I found that some hosting companies block database access from unknown IP addresses, so it's possible that you'll have to go to your CPanel and whitelist your IP address.
Once your database connection is setup, the code you use to query the database should look the same.
Some useful links:
JDBC Best practices
JDBC Tutorials from Oracle
Upvotes: 1
Reputation: 854
You have to change database url only to be like jdbc:mysql://IP:3306/databasename
also username and password.
some hosting company like godaddy create database in localhost(in the same host) which doesn't need to change anything in your code.
Upvotes: 1