2

I would like to connect my application via the internet to a server which has the MySQL Database.

How would I do that? And what's the Java Servlet to be used to connect?

david
  • 2,234
  • 1
  • 28
  • 44
wishman
  • 744
  • 3
  • 12
  • 29
  • 2
    I'm afraid you have completly misunderstood the concept of servlets. Take a look at this first: http://en.wikipedia.org/wiki/Java_Servlet – Wojtek Owczarczyk Feb 02 '12 at 08:08

3 Answers3

3

You can use java.net.URLConnection or the more convenienced Apache HttpComponents Client to interact with arbitrary web resources.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
2

I don't think using barebone servlets is the best way to acheive what you want. I would do something like this:

  • Create a new maven webapp archetype application
  • Add MySQL dependency
  • Add RESTLet or JAX-RS or Spring (version > 3.0) dependency and configure it to expose your data as RESTful web service. Lots of tutorials on the web.
  • Use RESTLet client on your Swing application to invoke your service.
Wojtek Owczarczyk
  • 5,206
  • 2
  • 27
  • 53
0

The most "modern" way to do this is using RESTful web service. I do not know how is your server side code built, but if I start to develop from scratch I'd use Spring framwork that has perfect support of REST web services.

AlexR
  • 109,181
  • 14
  • 116
  • 194