我正在将序列化的对象保存到mysql数据库blob。
在插入了一些测试对象,然后尝试查看表之后,我多次收到了大量的垃圾和"PuTTYPuTTY“。
我相信这与字符编码和包含奇怪字符的blob有关。
我只是想看看这是否会给我的数据库带来问题,还是仅仅是putty显示数据的问题呢?
对QuizTable的描述:
+-------------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+-------------------------------------------------------------------------------------------------------------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+-------------------------------------------------------------------------------------------------------------------+
| classId | varchar(20) | latin1_swedish_ci | NO | | NULL | | select,insert,update,references | FK related to the ClassTable. This way each Class in the ClassTable is associated with its quiz in the QuizTable. |
| quizId | int(11) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | This is the quiz number associated with the quiz. |
| quizObject | blob | NULL | NO | | NULL | | select,insert,update,references | This is the actual quiz object. |
| quizEnabled | tinyint(1) | NULL | NO | | NULL | | select,insert,update,references | |
+-------------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+-------------------------------------------------------------------------------------------------------------------+当我试图查看表中的内容时所看到的:
select * from QuizTable;
questionTextq ~ xp sq ~ w
t q1a1t q1a2xt 1t q1sq ~ sq ~ w
t q2a1t q2a2t q2a3xt 2t q2xt test3 | 1 |
+-------------+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
3 rows in set (0.00 sec)发布于 2011-10-20 02:52:18
我相信您可以在blobs和字符串上使用十六进制函数。您可以运行这样的查询。
Select HEX(quizObject) From QuizTable Where....发布于 2011-10-20 02:45:48
Putty是对它认为是输出流中的终端控制字符串的反应。这些字符串允许远程主机在不重新绘制整个屏幕的情况下更改本地终端的某些内容,例如设置标题、定位光标、清除屏幕等。
当试图“显示”像这样编码的东西时,很多二进制数据最终都会发送这些字符。
你也会得到这个反应的二进制文件。
blob将完全忽略任何字符编码设置。它真正的目的是存储二进制对象,如图像或压缩文件。
如果这个字段只包含文本,我建议使用文本字段。
https://stackoverflow.com/questions/7830286
复制相似问题