对于useUnicode和characterEncoding两个连接属性,下面介绍一点点:
useUnicode | Should the driver use Unicode character encodings when handling strings? Should only be used when the driver can't determine the character set mapping, or you are trying to 'force' the driver to use a character set that MySQL either doesn't natively support (such as UTF-8), true/false, defaults to 'true' |
characterEncoding | If 'useUnicode' is set to true, what character encoding should the driver use when dealing with strings? (defaults is to 'autodetect') |
因此,在连接中,我把连接的URL 从原来的:
jdbc:mysql://localhost:3306/[DBName]","[username]","[password]" 改成为:jdbc:mysql://localhost:3306/[DBname]?useUnicode=true&characterEncoding=UTF-8","[username]","[password]"。
经过这样子的改动以后,程序能够正常地输入中文值或作为条件参数。