By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

Insert to a database using java: problem with greek characters

P: 2
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
Share this Question
Share on Google+
2 Replies


Dheeraj Joshi
Expert 100+
P: 1,123
Can you please post the code here. I think it has to do something with the character encoding.

Regards
Dheeraj Joshi
Jan 18 '11 #2

P: 2
Thank you for the reply.

the part of the code is the following:

try
{
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true";
Connection con =(Connection) DriverManager.getConnection(url,"root", "");
con.setCharacterEncoding("utf-8");
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 +"')");
con.close();
}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.