Greek characters in database are like question marks("?????"). I can't find a solution. I developed an application using Java/Swing but when I insert Greek letters in MySQL are like question marks. I changed db collation to utf8 and the columns too. My project encoding is set to UTF-8. When I insert Greek letters from MySQL then they are stored properly.
I am using MySQL connector jar file.
public class Testing {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/chartest","root","1234");
Statement pst=conn.createStatement();
String var1="ασδασδ";
String sql="INSERT INTO chars(value) values('"+var1+"')";
pst.execute(sql);
} catch (SQLException ex) {
Logger.getLogger(Testing.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I think you just need to add a couple of more parameters (useUnicode
and characterEncoding
) when you create the connection. The following code works for me:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.PreparedStatement;
public class GreekTestMain {
public static void main(String[] args) {
String connUrl =
"jdbc:mysql://192.168.1.3/greektest?" +
"useUnicode=yes&characterEncoding=UTF-8" +
"&user=root&password=obfuscated";
try (Connection conn = DriverManager.getConnection(connUrl)) {
String sql = "INSERT INTO `chars` (`value`) VALUES (?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, "ασδασδ");
pst.executeUpdate();
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With