0

I'm doing a project with Matlab.

This project is about Thai license plate recognition.

I have a problem with encoding-utf8 (I guess).

The program can recognize and show data in Thai but inserting data in table can't show Thai character. (ex. กข1234 --> ??1234 )

I set collation in utf8_unicode_ci. Did i do anything wrong?

Thank you

Here is some of my code

%# Database
   javaaddpath('mysql-connector-java-5.1.6-bin.jar');
    host = 'localhost:3306';
   user = 'root';
   password = '';
   dbName = 'smart parking'; 

%# JDBC parameters
   jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);
   jdbcDriver = 'com.mysql.jdbc.Driver';

%# Create the database connection object
   conn = database(dbName, user , password, jdbcDriver, jdbcString);
    exec(conn, 'SET character_set_results=UTF-8');
    exec(conn, 'SET character_set_client=UTF-8');
    exec(conn, 'SET character_set_connection=UTF-8');
    exec(conn, 'SET character_set_server=UTF-8');
    exec(conn, 'SET NAMES utf8');

% check to make sure that we successfully connected

   if isconnection(conn) 
   SQL_x = ['SELECT * FROM tbl_information WHERE sPlate = ''' R_str ''' AND sOut = 0'];
   curs_x = exec(conn, SQL_x);
   curs_x = fetch(curs_x);
   QUERY_x = curs_x.Data;

       if strcmp(QUERY_x, 'No Data') == 1

          Plate = R_str;
          Sql = ['INSERT INTO tbl_information(sPlate, sTimeIn, sTimeOut, sUse, sPrice, sOut) VALUES(''' Plate ''', ''' datestr(now) ''', '''' , 0, 0, 0)'];
          curs = exec(conn, Sql); 


        end
   end

   set(handles.text8, 'String', R_str);
   drawnow;
6
  • Why are you using the ancient version 5.1.6 of the MySQL Connector/J driver? In any case, take a look at stackoverflow.com/questions/3040597/… Commented Apr 24, 2016 at 8:33
  • so if I use the new version of of the MySQL Connector/J driver, it would encode correctly? Commented Apr 24, 2016 at 10:11
  • Maybe, maybe not; I don't use MySQL that much, and I haven't tracked what they changed and fixed these past 8 years since the release of 5.1.6. Have you also checked the question I linked? AFAIK, you need to specify that connection property. Commented Apr 24, 2016 at 10:40
  • yes I have tried jdbc:mysql://localhost:3306/dbName?characterEncoding=utf8 but it doesn't work Commented Apr 24, 2016 at 10:52
  • You might need to use the useUnicode=true connection property in addition to characterEncoding=utf8. Commented Apr 24, 2016 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.