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,529
  • 1
  • 34
  • 50
wishman
  • 774
  • 4
  • 14
  • 31

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
  • 1,082,665
  • 372
  • 3,610
  • 3,555
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.
Wojciech Owczarczyk
  • 5,595
  • 2
  • 33
  • 55
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
  • 114,158
  • 16
  • 130
  • 208