Peace be upon you :)
Say I have:
ID Title
----- ---------------------------------------------------------------------
| 1 | Maher Zain - Peace Be Upon You - ماهر زين - عليك صلى الله (Official) |
----- ---------------------------------------------------------------------
Now I need to select this row using java JDBC.
The way I'm doing it right now:
String Title = null;
try {
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);
}
} finally {
if(ps != null)
ps.close();
if(rs != null)
rs.close();
if(con != null)
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
Connecting to DB:
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!");
}
}
This works But the output that I get is: ???? ??? ?????? ?????? - ???? ??????? - Maher Zain | Mustafa Ceceli - Bika Moulh
So I need to set the query to use Unicode character set.
I would really Appreciate if you tell me how <3