Java and MySql set unicode characters for this class -


i trying input unicode characters (greek) database. read in order have set unicode characters active. how can set character set unicode specific class?

public class database {      public static database busdatabase = null;      protected string connection_url = "";     protected string driver_name = "";     protected string name = "";     protected string user = "";     protected string password = "";     protected class driver_class = null;     protected static connection connection = null;     protected resultset results = null;     protected string current_table = "";     protected boolean error = false;      public database(string name, string user, string password) {                this(name, user, password, "jdbc:mysql://localhost:3306", "com.mysql.jdbc.driver");   }     //public void run() {   //   con =  (connection)drivermanager.getconnection(connection_url, user, password);  //}    public static boolean getcon() throws sqlexception   {       return  connection.isvalid(0);    }    public database(string name, string user, string password, string connection_url, string driver_name)   {     this.name           = name;     this.user           = user;     this.password       = password;     this.connection_url = connection_url;     this.driver_name    = driver_name;   }    public static void openbusdatabase()   {     try     {      busdatabase = new database("appointments", "root",               "27121993petros", "jdbc:mysql://localhost",               "com.mysql.jdbc.driver");             busdatabase.open();             system.out.println("dbopened");         } catch (exception ex) {             throw new invalidqueryexception("unable open database " + ex.getmessage());         }     } } 

pass parameter boolean make connection dynamically based on requirements. need encoding @ database end well, hope there.

based on condition change connectivity string.

change

  "jdbc:mysql://localhost", 

to

  "jdbc:mysql://localhost?useunicode=true&charactersetresults=utf8&characterencodi‌​ng=utf-8", 

optionally, collation can specified, such as: &connectioncollation=utf8_general_ci


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -