• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Java Client program requests Server program query MySql database?

 
Greenhorn
Posts: 11
MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming newbie here in need of some assistance.
(This is all using localhost)
I have made a Client program (with Java 8 and NetBeans) that queries a MySQL database directly. Whether the query is inserting data into the database or requesting data to fill the applications tables. I have tested to program multiple times and it seems to working just fine.
Now I want to put a middleman between the Client program and database by making a Server program that takes requests from the Client Program and in turn queries the MySQL database. If the request is to insert data. Then the server must help insert the data into the database. If the request is for data. Then the server must help pass data from the database to the client.
I did practice with servers and client programs. I made a client that sends messages to the server program which in turn sends the messages back to the client. The server can handle multiple instances of the Client program. I just have trouble applying it to the third part of the question, which is queries and databases
What direction must I now take? Syntax? Concepts? Advice?
 
Saloon Keeper
Posts: 14515
325
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

It sounds to me like you already have all the knowledge required. You know how to communicate between a Java application and a database, and you know how to communicate between two Java applications running on different machines. Now combine the two.

For a very simple CRUD application, RESTful APIs are excellent. I suggest you write a JAX-RS controller that accepts requests from your client, and then converts those requests to calls to a repository. This is roughly what it looks like:

Now, the repository class is the class that interacts with your database through a DataSource. You can create one like so:
 
Saloon Keeper
Posts: 26301
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Incidentally, what Stephan was recommending involves creating a web application that will run in a web server such as Tomcat. While you could design and implement any sort of server program you wanted, including RMI or raw network sockets, it's a lot easier when you have a good support system already coded, tested and debugged that you can plug into. Also, many of the non-web servers you could use or create might get blocked by firewalls, but web servers rarely are, so you don't get the frustration that comes when you do everything right and it still doesn't work!
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic