Q:

Adobe CQ5 - Populating drop down from external DB

I have a requirement to create a custom widget which will have drop down and few textfields. .The drop down should be populated by data which have been retrieved from external DB.
I have googled it but found no solution if any one has done any such thing then let me know please.

A:

There are several ways to go about this. The first consideration is how often your data changes from within the db, and what the lag is between the db and the cq5 server.
If the data does not change often, and it only needs to be updated either manually, or on a periodic basis, you can consider ingesting the information from the database, and then transforming it into a structure in the JCR. From there, you can use the out of the box json transformer in Sling, by hitting the node url, with the .json extension. I.e. the same way you see a content node as json localhost:4502/content/geometrixx/en.infinity.json
Assuming this is an author instance, you should consider putting the dropdown structure in the /apps directory if you want to hide it from the public in case it gets activated.
If you are publicly displaying the dropdown, a good place to put it is either in the /content directory in a structure, or if you consider it to be content more along the lines of application code, in an appropriate place in the /etc directory that is publicly available.
The second option, if you wish to be calling the database each time for the dropdown information, is to create a custom sling servlet, (See http://www.therealcq.blogspot.com.au/2013/01/how-to-write-custom-slingservlet.html to get a basic understanding).
There, establish a connection to the database, make the relevant SQL call, transform it to JSON and return it as an endpoint. If you are forcing it to have a .json extension, make sure that your dispatcher is not caching the answer inappropriately, as if you have taken this option, the data in the dropdown will either be contextual or fast moving.
Let me know if you need any elaboration on these solutions.

