java how to access a database that is in webserver across the internet?
If I have a database in a webserver开发者_如何学编程(over the internet) and i have a java desktop application, in how many ways can i access that database. Please could you provide me with links for detailed article.
It depends on the database, but...
Most databases will allow you to access them remotely. You specify the URL and port when you set up your database connection in your Java program.
However, if you do not have control of the database, then this can be difficult. It is also a BIG security risk, unless you lock down the access via the HOSTS value of the user_id you are connecting with.
There are other work-around approaches, like VPNs, Tunnels and even fronting the database with a Web Service, but none of these are likely to give you the same level of access that the first option will.
Here is the link from oracle:
http://download.oracle.com/javase/tutorial/jdbc/index.html
Its very simple and easy to follow.
I recomend to use Hibernate, it easy to define any URL, to any database provider in Hibernate config file.
E.g
property name="driverClassName" value="com.mysql.jdbc.Driver"/>
property name="url" value="jdbc:mysql://189.234.223.89:3306/dbname"/>
property name="username" value="root"/>
property name="password" value="pwd"/>
精彩评论