Here TESTKEY,TESTVALUES are the DB table fiedls.I have to retrieve the these values.count of the comma separated values has to get dynamically.
Hopefully the data isn't actually stored in the DB in CSV format like that. That isn't the way to store data unless users never need to see, query or work with the individual values.
Assuming that each value comes from a separate column just use JDBC to query the data and get a result set. Then add each column value to an ArrayList (or other collection). Then use the ArrayList as the 'value' of each 'key, value' pair.