2

Currently i tried by modifying my property file to insert those special characters.But its inserting as a question mark instead of ₹ Symbol please find below changes.

spring.datasource.url=jdbc:mysql://localhost:3306/dbName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&useUnicode=true&character_set_server=utf8mb4

My Entity column definition

@Column(name = "question", columnDefinition = "TEXT")
private String question;

I tried by doing

1.change in column definition to "nvarchar" i got hibernate error.

2.In mysql changed column definition to ALTER TABLE table CHANGE column column VARCHAR(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; referred, to change mysql tables definitions enter link description here

In case of any modification or mistake help me.

Mohan kumar
  • 123
  • 13
  • 1
    Look at `@Nationalized` annotation, it may help your problem [Annotation Type Nationalized](https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/annotations/Nationalized.html) – Ismail Durmaz Dec 16 '20 at 18:30
  • Hey thank you so much it's working after adding @nationalized. Please can you add it as a answer so that i can accept answer. – Mohan kumar Dec 17 '20 at 05:52

2 Answers2

2

Change the character encoding to utf8_general_ci by,

ALTER TABLE test_tb MODIFY COLUMN col VARCHAR(255)
    CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;

And then,

insert into test_tb values("₹");
Alien
  • 15,141
  • 6
  • 37
  • 57
  • Thank you for your response. When i try to insert from spring boot with the Column TEXT it's converting to ? i have changed to utf8_general_ci NOT NULL; in mysql but still same issue – Mohan kumar Dec 17 '20 at 05:46
1

Look at @Nationalized annotation, it may help your problem Annotation Type Nationalized

@Nationalized
@Column(name = "question", columnDefinition = "TEXT")
private String question;
Ismail Durmaz
  • 2,521
  • 1
  • 6
  • 19
  • 1
    Yes it worked before that required to do ALTER TABLE test_tb MODIFY COLUMN col text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; otherwise will throw getNstring() error.Thank you. – Mohan kumar Dec 17 '20 at 07:36