How to insert ₹(Special characters) into Database

Viewed 882

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.

2 Answers

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("₹");

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

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