i have to write small java database application with several tables. With that i have some experience and can do it. That would be on one machine.
From somewhere on net开发者_JAVA百科, from other machine it should have to be possible to connect and inspect some database queries in SWING GUI. That network part is with what i do not have experience. What would be best way to accomplish that task? I need some general directions here and maybe some good links with examples to study. Problem is i am kinda short with time here.
From my browsing i saw the most easiest solution is to connect direcly from distant machine directly with JDBC with ip:port way. Like 111.111.111.111:55 But that leaves DB really unsecure.
I've read about sockets, but i dont see how that helps.
Now, i've seen people mention Hibernate and VPN but i thinks that is lot of work. And others mention web servers, but i have absoulutely no idea how that works.
So, what is optimal solution in your oppinion? Ideas, suggestions, guidelines?
Thanks in advance, Martin.
JDBC drivers may have different arguments for their data source depending on if you use encryption for the connection.
For instance, MySQL allows you to use an SSL connection, and even has a section in its manual for it. Other databases may vary.
Presumably, your application will also have its own username and password to be sent to the remote DB server.
Some level of security will be provided by using a database login and password. If you are short on time then web services, or sockets aren't going to be quick to pick up. Unless you really need the security just use JDBC for now.
You have several options.
- RMI this allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine.
- CORBA Common Object Request Broker Architecture, is a standard architecture for distributed object systems. It allows a distributed, heterogeneous collection of objects to interoperate.
- Sockets
- HTTP server. You can use Servlets or some framework like Struts, Spring etc. for the server side and just call the servlet from your client using Apache HttpClient
Since you don't have much time I'd discard RMI and CORBA and focus on Sockets or the http server solution.
Since you wrote that you dont have experience with web applications I'd go with sockets.
With java you can create a server and client very easy using sockets here is a basic example and Here is a very good tutorial that uses Swing.
You probably want to write a Web service to expose your data instead of letting a user connect directly to the DB over the internet. Ideally that web service is on a physically seperate machine from the database, so that the database is not exposed to internet directly.
Person <--> internet <--> Web Service <--> database
It really depends on what you consider optimal.
Do you have zero concern for security?
if you're exposing a database directly onto the internet, you're going to have to open up ports on firewall/etc and secure your database, and pray you have no other insecure services exposed to the internet.
精彩评论