java向数据库中写入的问题

jhx497905872 2011-10-29 05:39:16
写了这样的程序

public void insertfilecon(String filename,String content,String tablename) throws SQLException, ClassNotFoundException, IOException
{
ConnectDB db = new ConnectDB();
Connection conn = db.getConnection();
PreparedStatement pstmt = null;
String sql = "INSERT INTO "+tablename+"(filename,content) VALUES (?,?)";
System.out.println(sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, filename);
pstmt.setString(2, content);
pstmt.executeUpdate();
pstmt.close();
conn.close();
}
在向数据库中插入简体中文和英文时没有问题但是繁体中文会出问题
Exception in thread "main" java.sql.SQLException: Incorrect string value: '\xE5\x9C\x8B' for column 'content' at row 1
请问如何解决这个问题?请各位大大指教....
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhx497905872 2011-10-29
  • 打赏
  • 举报
回复
字符集是utf8的...不可以么?
Inhibitory 2011-10-29
  • 打赏
  • 举报
回复
字符集的问题,把数据库改成UTF8试试

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧