I currently have a web service which has a class to connect to a MySQL database to get customer information that is stored.
What I would like to do is get all the customer information as in username and add them into a new item in a combobox in the client side. I know to use a Vector but I can’t get my head around how I can get the web service to go through each entry, send it back and then update the combo box without a bunch of messy cod.
Can anyone help me out here?
Thanks.
If you want to use a web service properly, you should use a List not a Vector. This will translate to multiple XML elements in your WSDL.
So for example if you have your web method named getCustomerInfo() and you are expecting it to return a list of strings, it would be like this:
Since you’re mentioning JDBC its unlikely that you actually need to return a String, but you’ll probably need a simple class which has 2 strings, the key and the value. For example ‘Username’ and ‘sandeep’.
Alternatively (the right way), use JPA and create a proper entity which reflects the proper table structure, and return that to the client. Thats why JPA was designed for EJB3, and giving you’re using Glassfish you’ve already got everything out of the box.
UPDATE (following comments discussion):
So essentially what you need to have is your webservice do something like this:
From the client side you will first need to generate the web service stubs, which will then give you the identical method getCustomerUsernames() to use.
For more info about web services and JAX-WS refer to the tutorial here