Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode, UTF-8, character encodings #1

Open
fjenett opened this issue Dec 16, 2012 · 3 comments
Open

Unicode, UTF-8, character encodings #1

fjenett opened this issue Dec 16, 2012 · 3 comments
Assignees
Labels

Comments

@fjenett
Copy link
Owner

fjenett commented Dec 16, 2012

Make sure this is taken account for:
http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-charsets.html

... there have been complaints about characters not showing up correct in Processing sketches. Review these and make tests to ensure it's not on our side.

@kosmos
Copy link

kosmos commented Dec 25, 2013

The problem arises when saving Unicode characters in the database. Below is an example. In the database, instead of Unicode characters get "?". Could you help me to solve this problem?

import de.bezier.data.sql.*;
import java.io.*;


static String user     = "root";
static String pass     = "root";
static String database = "test";
static String table    = "test";

MySQL msql;


void setup() {


  size(1024, 600);


  msql = new MySQL( this, "localhost:8889", database, user, pass );

  // Тестировании записи данных в базу
  if ( msql.connect() ) {
    msql.execute("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
    msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, TWEET TEXT)  default charset=utf8 ENGINE = MyISAM");
    msql.execute("SET NAMES utf8");
    msql.execute("INSERT INTO `test`.`test` (TWEET) VALUES ('Тестировании')");
    }

  exit();
}

void draw() {

}

@ghost ghost assigned fjenett Dec 25, 2013
@gilpark
Copy link

gilpark commented Jun 24, 2016

I hope you already found a way around it.
but for someone who has the same problem,
just use this class instead of MySQL class to your sketch till @fjenett fix it.

public class MySQL_UTF8 extends SQL
{  
  public MySQL_UTF8 ( PApplet _papplet, String _database )
  {
    // should not be used
  }


  public MySQL_UTF8 (  PApplet _papplet, String _server, String _database, String _user, String _pass)
  {
    super( _papplet, _server, _database, _user, _pass );
    init();
  }

  private void init ()
  {
    this.driver = "com.mysql.jdbc.Driver";
    this.type = "mysql";

    this.url = "jdbc:" + type + "://" + server +  "/" + database + "?useUnicode=yes&characterEncoding=UTF-8";

  }

  public String[] getTableNames ()
  {
    if ( tableNames == null ) 
    {
      tableNames = new ArrayList<String>();
      query( "SHOW TABLES" );
      while ( next() ) {
        tableNames.add( getObject("Tables_in_"+database).toString() );
      }
    }
    return tableNames.toArray(new String[0]);
  }
}

@fjenett
Copy link
Owner Author

fjenett commented Jun 25, 2016

Thanks

fjenett pushed a commit that referenced this issue Jan 8, 2023
fjenett pushed a commit that referenced this issue Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants