I'm using prepared statements to insert an array into my database
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO TABLE(stringArray) VALUES (?)");
String[] arr = { "a", " b", "c" };
pstmt.setObject(1, arr);
I'm using setObject following an example, but setArray won't resolve and setBlob doesnt work either.
Now when i come to read it, I'm not sure what to do with my object to get the array values back!
PreparedStatement pstmt = conn.prepareStatement("SELECT stringArray FROM TABLE WHERE id = 1");
ResultSet rs = pstmt.executeQuery();
rs.next();
Object object = rs.getObject(1);
System.out.println(object.toString());
Just outputs
[B@45d0e784
I know i'm doing object.toString and i want an array, but how would i do that? do i need to set it as a byte or something when inserting?
Thanks for your help