469,950 Members | 2,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Insert to a database using java: problem with greek characters

I'm writing a java programme, which connects to a database in my computer(using jdbc). The database is allowed to use greek characters and I can check that, because when I use a "select" query, the text appears as it should. But when I try to insert new data, instead of greek characters, the result in the database is only some questionmarks. Where is the problem? (I've already defined the collation as utf-8)
Jan 18 '11 #1
2 3452
Dheeraj Joshi
1,123 Expert 1GB
Can you please post the code here. I think it has to do something with the character encoding.

Dheeraj Joshi
Jan 18 '11 #2
Thank you for the reply.

the part of the code is the following:

Statement stmt;
ResultSet rs;
String url ="jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true";
Connection con =(Connection) DriverManager.getConnection(url,"root", "");
stmt = (Statement) con.createStatement();
stmt.executeQuery("SET NAMES 'UTF8'");
stmt.executeQuery("SET CHARACTER SET 'UTF8'");
String greekname = "κωνσταντίνα";
stmt.executeUpdate("INSERT INTO user2(userid,username) VALUES ('" + "1" + "','" + greekname +"')");
}catch( Exception e ) {System.out.println("problem during the connection with the database!");}

The result in the table user2 is userid:1 and username:???????????
By the way, when i try to insert the same data using php, everything runs ok. However, i need to do this using java.
Jan 18 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Frank Maestas | last post: by
4 posts views Thread by Giannis Vrentzos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.