1。显示'%character%set%';
2. 我的表:
CREATE TABLE `t_languagetable`
(
`id` INT(11) NOT NULL,
`languagecode` VARCHAR(2) NOT NULL,
`countrycode` VARCHAR(2) NULL DEFAULT NULL,
`variant` VARCHAR(10) NULL DEFAULT NULL,
`language` VARCHAR(50) NOT NULL,
`displayname` VARCHAR(50) NOT NULL collate
'utf8_general_ci',
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci' engine=innodb ;
3. 我的java代码:
Connection connect = null;
Statement statement = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://192.168.99.211/"
+ databaseName + "?"
+ "user=" + username
+ "&password=" + password);
statement = connect.createStatement();
String displayName = "Русский";
String insertSql = "INSERT INTO t_languagetable " +
"VALUES (" + 1 + ", 'va', null, 'null', 'null' ," + "'" + displayName + "'" + ")";
statement.executeUpdate(insertSql);
System.out.println("insertSql: " + insertSql);
connect.close();
} catch (Exception e) {
System.out.println("problem during the connection with the database!"+e);
}
4. 结果:
答案 0 :(得分:1)
解决。
您已尝试在setNString
中的插入时间displayname
更改方法,不要在数据库中更改...!
尝试这种方式
Connection connect = null;
Statement statement = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://127.0.0.1/"+databaseName+"?user="+username+"&password="+password);
PreparedStatement prep = connect.prepareStatement("INSERT INTO t_languagetable (id,languagecode,displayname) VALUES (?,?,?)");
prep.setInt(1,7);
prep.setString(2,"AA");
prep.setNString(3,"Русский");
prep.execute();
System.out.println("Data Inserted.");
connect.close();
} catch (Exception e) {
System.out.println("problem during the connection with the database!"+e);
}