mysql - how do i get greek characters in my database using jsp -


i'm trying insert greek names in database using jsp programme. however, result in database "????" instead of greek characters. if try insert greek name using phpmyadmin or command line, there no problem. guess there trouble in jsp code. here simple part of code:

try

    {     statement stmt;     resultset rs;     class.forname("com.mysql.jdbc.driver");     string url ="jdbc:mysql://localhost:3306/test?useencoding=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 users(name,age) values ('" + greekname + "','" + "44" +"')");     con.close();         }catch( exception e ) {system.out.println("problem during connection database!");} 

i hope has idea it!

however, result in database "????" instead of greek characters

the database table when retrieves characters not covered character encoding database table been instructed store characters with. need ensure database , table created follows:

create database db_name character set utf8; create table users (...) character set utf8; 

see also:


unrelated concrete problem, loading driver on every query unnecessary. once during application's startup enough. also, closing of resources should happen in finally block, else risk resource leaks in case of exceptions. finally, writing raw java code in jsp file not best practice ;)


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -