-2

Recently I am trying to create a java application which will access my web database. I want to send some data from my local pc application to server database and even I want to download some data from the web database.

Is there any suitable method to follow. I know its possible but don't know how.

I'm going to use language for application is pure Java.

for the web i will use PHP, MySQL, JSON, or even plain text

Is there any method to access the web url with get or post method. and receive the data from that page.

or there is any way to make a connection between the web address from java.

Makoto
  • 96,408
  • 24
  • 164
  • 210
  • 1
    You should implement a sort of web services. I.e. web pages that interrogate the database and return a json. You can use Java to ask for this web pages then. Clearly, username and password as well as https are suggested. – mat_boy Jul 03 '14 at 07:13
  • Or simple call the web server using some kind of Web RPC protocol – MadProgrammer Jul 03 '14 at 07:14
  • @MadProgrammer Sure! It depends on the kind of hosting service. Sometimes this is not possible. – mat_boy Jul 03 '14 at 07:15
  • @mat_boy This all assumes that the OP controls the web service. Using a simple HTTP GET and returning JSON is done all the time, 90% of web services I have to code against do this kind of thing :P – MadProgrammer Jul 03 '14 at 07:19
  • @MadProgrammer Right! However, he should use something like RMI in java, or an EJB application. – mat_boy Jul 03 '14 at 07:20
  • @mat_boy Why? You could establish this `Servlet`s quite easily. RMI has too many issues over firewalls, routers and virtual networks, just saying ;) – MadProgrammer Jul 03 '14 at 07:22
  • @MadProgrammer Again, I do agree with you! But he asked for solutions, I'm just listing all of them. The best approach for me is based on EJB. The simplest and cost-effective is based on PHP-JSON-JAVA. RMI is just another way... I do not recommend it. – mat_boy Jul 03 '14 at 07:24
  • There are lots of ways to access a web URL, `java.net.URL` is one Apache HTTP Components (HTTP Client in particular) is another – MadProgrammer Jul 03 '14 at 07:30

2 Answers2

1

A first idea is to implement a web service. E.g.

  1. A PHP page is implemented to interrogate the database based on the query string.
  2. The http request to the PHP page must return a structured data (JSON, XML, etc.)
  3. The Java application can ask for the web page and get the result (see this post for instance).

Another approach suggested by MadProgrammer is to interact directly with the application server by using the Remote Procedure Call (RPC) protocol. E.g., you can implement an EJB application. Notice that this is not possible with basic hosting service.

In this context, a simplest application could be based on RMI. This is a pretty easy approach, since you only need to implement two java classes that interact via the Internet (one in the server, the other in the client). But again, sometimes this is not possible with basic hosting service.

Community
  • 1
  • 1
mat_boy
  • 10,930
  • 19
  • 62
  • 103
1

Is there any method to access the web url with get or post method. and receive the data from that page.

or there is any way to make a connection between the web address from java.

There are a number of possible ways you could do this...

There are probably others, but these are the ones I can think of...

These would allow you send and receive data to/from a server, its then up to you to parse the result.

If you're using JSON, Gson is a popular library

MadProgrammer
  • 323,026
  • 21
  • 204
  • 329