A web service is for two applications to communicate with each other. So, what you are looking for is a bit confusing.
You can simply create a Java application that connects to a database and retrieves data.
Then, you can create a web service that communicates with the application above.
Then the client applications that need data from the database use the web service to connect to the other application that retrieves the data.
client application ----> web service ----> Java application that gets data
The most important thing here is to recognize that the code of the web service does not contain the database access and data retrieval code. The code of the web service only serves to allow the two applications to communicate with each other using SOAP over HTTP. That is all.