Open fjenett opened 11 years ago
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() {
}
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]);
}
}
Thanks
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.