I have a set of array value, i want to insert into database but it comes out with the result that I don't want.
I wish my database can store like this:
id_code | id_description
---------------------------
PO1 | hello
PO2 | hi
but as I run the code, it store like this:
id_code | id_description
-----------------------------------
[PO1,P02] | [hello, hi]
Here is the coding:
public void addID(IDInfo IDInformation) {
try {
PreparedStatement preparedStatement = connection
.prepareStatement("INSERT INTO id (id_code, id_description)"
+ "VALUES (?, ?)");
preparedStatement.setString(1, Arrays.toString(IDInformation.getIDCode()));
preparedStatement.setString(2, Arrays.toString(IDInformation.getIDDescription()));
preparedStatement.executeUpdate();
}
}
catch (SQLException e){
e.printStackTrace();
}
}
Controller:
String action = request.getParameter("action");
IDInfo idInfo = new IDInfo();
String[] Code = request.getParameterValues("idCode");
String [] Describe = request.getParameterValues("idDescription");
idInfo.setidCode(Code);
idInfo.setidDescription(Describe);
How is this caused and how can I solve it?