public static void main(String[] args) throws SQLException, UnsupportedEncodingException {
// TODO Auto-generated method stub
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e){
e.printStackTrace();
}java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/movie?useUnicode=true&characterEncoding=gb2312", "root", "root");
java.sql.Statement stmt = conn.createStatement();String sql;
sql = "insert into movie_5th(num, week_begin, week_end, name, firstchk, secondchk) values ('111', '2011-04-07', '2011-04-12', '卧虎藏龙', '审核员1', '审核员2')";
stmt.executeUpdate(sql);
java.sql.ResultSet rs = stmt.executeQuery("select * from movie_5th");while(rs.next()){
//System.out.println(rs.getInt(1));
System.out.print(rs.getString("num") + " ");
System.out.print(rs.getString("week_begin") + " ");
System.out.print(rs.getString("week_end") + " ");
System.out.print(rs.getString("name") + " ");
System.out.print(rs.getString("firstchk") + " ");
System.out.println(rs.getString("secondchk"));}
rs.close();
stmt.close();
conn.close();}
已设置表的字符集,GB2312。
在MyEclipse上运行,提示的错误信息如下:
Exception in thread "main" java.sql.SQLException: Incorrect string value: '\xCE\xD4\xBB\xA2\xB2\xD8...' for column 'name' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
at mysql.MySQL.main(MySQL.java:26)
请大虾帮忙看看!