0

Basically I have Column row with the value of:

   ID            Title
 ----- ----------------------------------
|  1  |ماهر زين - عليك صلى الله (Official) |
 ----- ----------------------------------

-

String Title = null;
DBConnect Database = new DBConnect();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
    con = Database.getcon();
    String query2="SELECT TITLE FROM table WHERE ID=?";
    ps = con.prepareStatement(query2);
    ps.setInt(1, 1);
    rs=ps.executeQuery();
    if(rs.next()){
        Title=rs.getString(1);
        System.out.println(Title);
    }
} finally {
    if(ps != null)
        ps.close();
    if(rs != null)
        rs.close();
    if(con != null)
        con.close();    
}

To connect to the DB I Do:

public DBConnect(){
    try{
        Class.forName("com.mysql.jdbc.Driver");

        String unicode="useSSL=false&useUnicode=yes&characterEncoding=UTF-8";
        con = DriverManager.getConnection("jdbc:mysql://localhost:15501/db?"+unicode, "root", "pwd");
        st = con.createStatement();
    }catch(Exception ex){
        System.out.println(ex.getMessage());
        System.out.println("couldn't connect!");
    }
}

But the Output I get is: ????? ??? ????? ? ??? ?? ????? (Official)

I also have tried:

ALTER DATABASE <name> CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

- I also tried:

select 
c.character_set_name 
from information_schema.tables as t,
 information_schema.collation_character_set_applicability as c
where c.collation_name = t.table_collation
and t.table_schema = "duckdb"
and t.table_name = "stackscontents";

The output I get is `utf8mb4

FYI: My my.ini file says default-character-set=utf8

Yet still i'm getting the output as: ????? ??? ????? ? ??? ?? ????? (Official)

All replies are much appreciated

12
  • What device are you outputting to? Commented Jun 18, 2017 at 22:16
  • where did you print this output? Commented Jun 18, 2017 at 22:18
  • @MaartenBodewes if you mean OS, I am using windows (8.1) x64 PC, MySql 57, and the output i get is from Eclipse IDE, at if(rs.next()) Commented Jun 18, 2017 at 22:19
  • This link could be of assistance: stackoverflow.com/questions/5405236/… Commented Jun 18, 2017 at 22:23
  • In order to see whether the retrieved from the database is wrong, or the output to the console, dump the string like System.out.println(s.codePoints().collect(Collectors.toList())); Commented Jun 18, 2017 at 22:25

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.