Java Help: Save a Key-Value Arraylist in a BD

Asked

Viewed 81 times

-4

I would like to know how to save a key and value Arraylist in the database using Java;

I had already made an implementation earlier in php similar, whose I created the array and used the function json_encode($array) to transform the array into a string and json_decode($array_string) to convert the string to an array.

I would like to know a similar method that you can use in Java, remembering that it is a key-value array.

Battered.

  • Could [Edit] the question with examples of data that are in the ArrayList? I say this because in PHP an array can be either a sequential list or a set of key/value pairs, but in Java the structures are separated: ArrayList is only a list of elements, and for key pairs/value is used Map. Anyway, the best way to write to the bank will depend on how the data is. Not always turning into a JSON is the best solution, but without knowing how the data is, can not help much...

1 answer

0


The easiest way would be to implement this information in the Entity model and save using Hibernate, it’s really simple. Since your list would be an entity list and to save just one . save() in the entity, if Hibernate is correctly configured. If you are used odbc connector and pure query, I cannot imagine a very practical way other than to make a go and create a "stringona" and then run the Insert. A tip, if using KEY|VALUE in java we usually use MAP<> and not the list.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.