Lets say I have one column with datatype of VARCHAR(500) in db2 zOS table and I wanted to insert data into that column using prepared statement. But that data/string has null character in between. e.g: "hello\0test\0example!". My question is does setString(index, str) will change those null characters with space or any other character ? or will get it inserted as it is ?
I tried inserting data but not sure. I found change in hex values of original string and inserted string.
'\0' in Java is considered null. Answering your question, your string will be inserted as-is. It will have null inside. It will then be dependent on your DBMS in your case 'db2' that how it will handle null inside string.
I have tested it using MySQL . I am getting the same data which is inserted. Additionally I have verified it using char instead of String and by printing their ascii values which is just an additional check.
I have used this code for printing every character value:
To test it with database I have first printed your given string and save in database, then extracted it and got it printed (deletion is for my own testing). I have tested following code with MySQL utf8 default colation :
Interestingly, I have found out that System.out.println() prints until it finds '\0' (like c), however prepared statement inserts complete string with length.