在jsp中向mysql中插入中文数据时提示错误:java.sql.SQLException: Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'Stu_name' at row 1以下是我的代码,希望大侠帮忙指出原因,谢谢。<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%!
String tbl="";
%>
<%
Connection con;
Statement stmt;
ResultSet rs;
try
{
Class.forName("com.mysql.jdbc.Driver");
String dburl="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8";
con=DriverManager.getConnection(dburl,"root","sa" );
stmt=con.createStatement();
int i=stmt.executeUpdate("insert into t_student(id,stu_name,stuno) values (3,'张三','88')");
}
catch(Exception e)
{
}
%></body>
</html>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%!
String tbl="";
%>
<%
Connection con;
Statement stmt;
ResultSet rs;
try
{
Class.forName("com.mysql.jdbc.Driver");
String dburl="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8";
con=DriverManager.getConnection(dburl,"root","sa" );
stmt=con.createStatement();
int i=stmt.executeUpdate("insert into t_student(id,stu_name,stuno) values (3,'张三','88')");
}
catch(Exception e)
{
}
%></body>
</html>
你可以用命令查一下。
方法一,重新安装数据库,再次安装的时候注意编码方式选择utf-8
方法二,ALTER TABLE `xxx` DEFAULT CHARACTER SET utf8 忘了命令到底行不行,楼主自己找找看吧!