Hello,

I have Googled this for days, but couldn't find a suitable code/tutorial. I need to write a simple java webservice that would return a XML/JSON file as its output.

For example say there's a button, and when i click on it, it should run a SQL

select * from store

query and return me the results in the format of a XML/JSON file.

Is there any tutorial or sample code for me to follow. Please help.

The term you should be looking for is Java RESTful framework. These frameworks basically allow you to create xml/json/XXX enabled HTTP services by mapping your output object to XML/JSON elements. There are a few frameworks which I'm aware of (but never used):
* Restlet
* Resteasy
* Jersey

The tutorial which uses RestEasy can be found here.

EDIT: Found that this was cross-posted at: http://stackoverflow.com/questions/8229718/webservice-return-a-xml-json-file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.