How to Store Array of Objects in Sql Table Column of String Type in Java?

How to Store Array of Objects in Sql Table Column of String Type in Java?

I have a table EMPLOYEE_PREF in ORACLE SQL. It has columns EMP_ID, EMP_KEY, EMP_TYPE, EMP_VALUE Basically EMP_VALUE is a string. It is a bookmarked url.

I have to re-use the table for Employee's preference on selection. The selection is Array of objects. Facility, Healthplan, .. Each of the object has key,value pairs: Ex for Facility object

    {   dataType : "string"
        isEligible : true
        label : "Facility Name"
        name :"facilityName"
    }
    {
       ...
    }

Now I am not getting how to store the Array of objects in EMP_VALUE column which stores VARCHAR.

Please help me with some solution. I should be able to store in String and retrieve in array of objects.

1

2 Answers

I dont think if it is possible. You can store current object's reference though but it doesnt make much sense. In next run the object will change. What do you mean by bookmarked url?

Instead you can use some format to store the preferences under each category..for eg [Facility=(isEligible : true, name :"facilityName",..)] something like this. To retrieve it back you would have to crack it in reverse way.

Note : Consider changing your DB design, and add preferences for each category under different column. That will make your life much easier.

What is your database? When you need to store a large amount of text, in this case is what you are doing, you can just use in Oracle the TEXT type, in SQL Server, since SQL Server 2005, you can use the VARCHAR(MAX) or TEXT for older versions. In these types, you can store the text as an array, once you convert to an String as this example:

List<String> strings = new ArrayList<String>();
strings.add("String 1");
strings.add("Strings 2");
strings.add("Strings 3");


String token = strings.toString();

Then you can put the String token on database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.