How to convert GBK charset to UTF-8 and insert data in MySQL?


#1

Hello everybody

Could you give simple way to conver text loaded from web with GBK charset to UTF-8 and after insert data in mysql table (UTF-8 charset for table)

There is how I get content with GBK charset:

var content = URL(“http://somesite.ch”).readText(Charset.forName(“GBK”))

There is how insert:
var connection = DriverManager.getConnection(url, user, password)
var stm = connection.prepareStatement(query)
stm.setString(1, content)
stm.executeUpdate()

If print data I get -> 女式上装

After inserting I get ???


#2

Solved

DriverManager.getConnection(url, user, password)


url have to content of jdbc:mysql://localhost:3306/database?useUnicode=yes&characterEncoding=UTF-8

FYI when I do
.readText(Charset.forName(“GBK”))

I get content in Unicode format already

After I need say DB connection to work with Unicode