How to save String[] in Mysql

Asked

Viewed 144 times

3

Hello, I’d like to save one String[] in Mysql, but I don’t know the type of datatype that saves String[], and what method I use to store this information.

  • Have you studied about JDBC, Hibernate or some way to integrate java code with DBMS?

  • @Douglas no, not yet.

  • 1

    I recommend studying about it. It is no secret, but it will be better for you :)

  • Has some specific content about String[] ??

  • As I explained to you, it is better to read it, because it is a very complex area. :)

  • @Lucascarezia I would particularly save in the bank as a single table, separated each Dice from the array by a comma in the bank. Example: value1,value2,Valor3.

  • Since array is an attribute with multi-valued data, ideally you would have a separate table for each array information, where each tuple would have the foreign key referencing who holds the array.

Show 2 more comments

1 answer

0

I assume you are using the Java and JDBC language for database access, but it was not very well specified.

But you can do something like this: String[] array = { "java", "JDBC", "Hibernate" };

String vectorString = Arrays.toString(array); //a string will be: [java, JDBC, Hibernate]

Then save the String vector in the database as VARCHAR type. It is an option, but I advise to study about ORM and object persistence.

  • And when taking from the Database, how to turn into String[] again ??

Browser other questions tagged

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