Peter Peter - 1 year ago 107
MySQL Question

Java and MySql set unicode characters for this class

I am trying to input unicode characters (greek) to my database. However I read that in order to do so I have to set the unicode characters to active. How can I set the character set to unicode for the 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)
{ = name;
this.user = user;
this.password = password;
this.connection_url = connection_url;
this.driver_name = driver_name;

public static void openBusDatabase()
busDatabase = new database("appointments", "root",
"27121993petros", "jdbc:mysql://localhost",
} catch (Exception ex) {
throw new InvalidQueryException("Unable to open database " + ex.getMessage());

Answer Source

Pass a parameter as boolean to make the connection dynamically based on your requirements. You will need encoding at database end as well, I hope that is already there.

Based on the condition change the connectivity string.




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download