Bonjour à tous,

Finalement je me suis décidé à afficher ici après plusieurs frustrantes journée à tenter de régler le problème.

Le voici.

J'ai une BD MySQL qui a une rangé qui contient des données avec des accents :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
mysql> select * from cb_message_text where lang_code = 'fr' and mssg_id = 91;
+---------+---------+-----------+--------------+
| mtxt_id | mssg_id | lang_code | message_info |
+---------+---------+-----------+--------------+
|     127 |      91 | fr        | aéè        |
+---------+---------+-----------+--------------+
1 row in set (0.00 sec)
 
mysql> show create table cb_message_Text;
cb_message_Text | CREATE TABLE `cb_message_Text` (
  `mtxt_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `mssg_id` bigint(20) NOT NULL,
  `lang_code` varchar(5) NOT NULL,
  `message_info` varchar(255) NOT NULL,
  PRIMARY KEY (`mtxt_id`),
  UNIQUE KEY `mtxt_uk_1` (`mssg_id`,`lang_code`)
) ENGINE=MyISAM AUTO_INCREMENT=129 DEFAULT CHARSET=latin1
 
mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 |
| character_set_connection | latin1 |
| character_set_database   | latin1 |
| character_set_filesystem | binary |
| character_set_results    | latin1 |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.00 sec)
 
mysql>
L'insertion de la rangée s'est effectué à partir de MySQL directement avec un simple "insert ...".

Donc dans MySQL, pas de problèmes.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
mysql> select hex(message_info) from cb_message_text where lang_code = 'fr' and mssg_id = 91;
+-------------------+
| hex(message_info) |
+-------------------+
| 61C3A9C3A8        |
+-------------------+
1 row in set (0.00 sec)
 
mysql>
Lorsque j'accède à cette données en Java dans Tomcat, je reçoit :

Hex : 61CCA9CCA8

Qui n'affiche rien de sensé !!!

Ou dois-je commencer à regarder ? Ma classe Java est bien simple pourtant

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
	static final String HEXES = "0123456789ABCDEF";
	private String getHex( byte [] raw ) {
	    if ( raw == null ) {
	      return null;
	    }
	    final StringBuilder hex = new StringBuilder( 2 * raw.length );
	    for ( final byte b : raw ) {
	      hex.append((char)b);
	      if (b > 127 || b < 0) {
	          hex.append('(');
	          hex.append(HEXES.charAt((b & 0xF0) >> 4))
	             .append(HEXES.charAt((b & 0x0F)));
	          hex.append(')');
	          hex.append(' ');
	      }
	    }
	    return hex.toString();
	  }
 
	public String getTranslation(String langCode, String code) {
		try {
			// code = "pour du personnel qualifie au bon moment...";
			// langCode = "fr";
			PreparedStatement s = this.conn.prepareStatement(
					"SELECT message_info " +
					"  FROM cb_message mssg, " +
					"       cb_message_text mtxt " +
					" WHERE mssg.code = ? and " +
					"       mtxt.mssg_id = mssg.mssg_id and " +
					"       mtxt.lang_code = ?");
			s.setString(1, code);
			s.setString(2, langCode);
			ResultSet rs = s.executeQuery();
			if (rs.next()) {
			    return getHex(rs.getString(1).getBytes());
				//return rs.getString(1);
			} else {
				return "Message not found code=(" + code + ") language=(" + langCode + ")"; 
			}
		}
		catch  (Exception e2) {
			e2.printStackTrace();
		}	
		return "Not found";
	}
Bon maintenant j'ai essayé dans l'autre sens... j'ai inséré des données dans la BD par un programme JAVA que voici :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.sql.*;
 
public class Jdbc10 {
	public static void main(String args[]) {
		System.out.println("Copyright 2004, R.G.Baldwin");
		try {
			Statement stmt;
			ResultSet rs;
 
			// Register the JDBC driver for MySQL.
			Class.forName("com.mysql.jdbc.Driver");
			//String url = "jdbc:mysql://localhost:3306/JunkDB";
			String url = "jdbc:mysql://localhost:3306/cvbank?characterEncoding=UTF-8";
 
			Connection con = DriverManager.getConnection(url, "cvbank_web",
					"webpass");
			// Display URL and connection information
			System.out.println("URL: " + url);
			System.out.println("Connection: " + con);
 
			// Get a Statement object
			stmt = con.createStatement();
			try {
				stmt.executeUpdate("DROP TABLE myTable");
			} catch (Exception e) {
				System.out.print(e);
				System.out.println("No existing table to delete");
			}// end catch
			stmt.executeUpdate("CREATE TABLE myTable(test_id int,"
					+ "test_val char(15) not null)");
			stmt.executeUpdate("INSERT INTO myTable(test_id, "
					+ "test_val) VALUES(1,'One é')");
 
			stmt.executeUpdate("INSERT INTO myTable(test_id, "
					+ "test_val) VALUES(2,'Two à')");
			stmt.executeUpdate("INSERT INTO myTable(test_id, "
					+ "test_val) VALUES(3,'Three ç')");
			stmt.executeUpdate("INSERT INTO myTable(test_id, "
					+ "test_val) VALUES(4,'Four')");
			stmt.executeUpdate("INSERT INTO myTable(test_id, "
					+ "test_val) VALUES(5,'Five')");
			stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			rs = stmt.executeQuery("SELECT * "
					+ "from myTable ORDER BY test_id");
 
			System.out.println("Display all results:");
			while (rs.next()) {
				int theInt = rs.getInt("test_id");
				String str = rs.getString("test_val");
				System.out.println("\ttest_id= " + theInt + "\tstr = " + str);
			}// end while loop
			System.out.println("Display row number 2:");
			if (rs.absolute(2)) {
				int theInt = rs.getInt("test_id");
				String str = rs.getString("test_val");
				System.out.println("\ttest_id= " + theInt + "\tstr = " + str);
			}// end if
			//stmt.executeUpdate("DROP TABLE myTable");
			rs = stmt.executeQuery("SELECT message_info "
					+ "from cb_message_text where lang_code = 'fr' and mssg_id = 91");
			System.out.println("Display application results:");
			while (rs.next()) {
				String str = rs.getString("message_info");
				System.out.println("\tmessage_info=[" + str + "]");
			}// end while loop
			con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}// end catch
	}// end main
 
}
et lorsque je selectionne les résultats dans MySQL :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mysql> select hex(test_val) from myTable where test_id = 1;
+---------------+
| hex(test_val) |
+---------------+
| 4F6E6520E9    |
+---------------+
1 row in set (0.00 sec)
 
mysql> select * from myTable;
+---------+----------+
| test_id | test_val |
+---------+----------+
|       1 | One ?    |
|       2 | Two ?    |
|       3 | Three ?  |
|       4 | Four     |
|       5 | Five     |
+---------+----------+
5 rows in set (0.00 sec)
 
mysql> quit
Donc il y a un ajustement de configuration à faire. Soit dans l'engin MySQL, soit dans ma connection JDBC.