0

I have a byte array as shown below,

byte b1[] = {-127, -87, -32, -112};

when I'm trying to convert it to a String it's showing black diamond like character, I want to insert it in the database.

Which charset should I use for database?

I have tried utf8mb4 and CP1250? I'm using mysql version 5.7.14 ?

Given below error while inserting:

java.sql.SQLException: Incorrect string value: '\xEF\xBF\xBD\xEF\xBF\xBD...' for column

Here is the code:

   byte b1[] = {-127, -87, -32, -112};
   TRNRequest tr = new TRNRequest();
   tr.set(new String(b1));
   trnRequestService.saveTransactionRequest(tr);

trnRequestService is dao layer service which stores object in database and TRNRequest is my class, I am using Hibernate for database connection. I want to read this character

public class DbByteInsert {
        public static void main(String[] args) {
             System.out.println(new String(new byte[]{ 48, 50}));
             System.out.println(new String(new byte[]{ -127, -87, -32, -112}));
        }
}

check this example I am able to insert first byte array in db but I can not insert second..!

Shailesh
  • 657
  • 2
  • 13
  • 27

0 Answers0