달력

122021  이전 다음

  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
으악 DB에 한글이 안들어가요.

Exception in thread "main" java.sql.SQLException: Incorrect string value: '\xEB\xB0\xB1\xEA\xB8\xB0...' for column 'name' at row 1

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)

at springbook.user.dao.UserDao.add(UserDao.java:23)

at springbook.user.dao.UserDao.main(UserDao.java:60)



mysql> SHOW VARIABLES LIKE '%olla%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

mysql> 

Class.forName("com.mysql.jdbc.Driver");

Connection c = DriverManager.getConnection("jdbc:mysql://localhost/springbook?characterEncoding=UTF-8", "spring","book");


방법을 찾았습니다만, 쉽지 않은 문제였습니다. DB에 대한 이해가 필수겠지요. varchar(20)을 longtext  로 잡았습니다.

create table users (

id varchar(10) primary key,

name longtext not null,

password varchar(10) not null

) DEFAULT CHARSET=utf8;



현재 DB 설정과 내용은 다음과 같습니다.
kenuheoyimacbookpro-4:bin kenu$ ./mysql -u spring -p springbook
Enter password: 
...
Server version: 5.5.8 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
...
mysql> show variables like '%olla%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

mysql> select * from users;
+-----------+-----------+----------+
| id        | name      | password |
+-----------+-----------+----------+
| whiteship | 백기선    | married  |
+-----------+-----------+----------+
1 row in set (0.00 sec)

mysql> 



Posted by 케누 kenu허광남

댓글을 달아 주세요

  1. 알 수 없는 사용자  댓글주소 수정/삭제 댓글쓰기 2011.01.07 13:31

    전 그냥 영문으로 코드 돌렸는데요.. ㅎㅎㅎ
    일일이 다 해결하셨군요...