这是源代码:
public class addStudent{
public static void main(String[] args) {
Student stu = new Student();
stu.setSid(1);
String str = "中国";
stu.setSname(str);
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tr = session.beginTransaction();
try {
session.save(stu);
tr.commit();
} catch (Exception e) {
// TODO: handle exception
tr.rollback();
e.printStackTrace();
}
finally{
session.close();
}
}
}
下面是报的异常:
2011-03-23 18:35:05 Hibernate 3.3.2.GA
2011-03-23 18:35:05 hibernate.properties not found
2011-03-23 18:35:05 Bytecode provider name : javassist
2011-03-23 18:35:05 using JDK 1.4 java.sql.Timestamp handling
2011-03-23 18:35:06 configuring from resource: /hibernate.cfg.xml
2011-03-23 18:35:06 Configuration resource: /hibernate.cfg.xml
2011-03-23 18:35:06 Reading mappings from resource : com/pojos/student.hbm.xml
2011-03-23 18:35:06 Mapping class: com.pojos.Student -> student
2011-03-23 18:35:06 Configured SessionFactory: null
2011-03-23 18:35:06 Using Hibernate built-in connection pool (not for production use!)
2011-03-23 18:35:06 Hibernate connection pool size: 20
2011-03-23 18:35:06 autocommit mode: false
2011-03-23 18:35:06 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=GBK
2011-03-23 18:35:06 connection properties: {user=root, password=****}
2011-03-23 18:35:06 RDBMS: MySQL, version: 5.1.45-community
2011-03-23 18:35:06 JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
2011-03-23 18:35:06 Using dialect: org.hibernate.dialect.MySQLDialect
2011-03-23 18:35:06 Using default transaction strategy (direct JDBC transactions)
2011-03-23 18:35:06 No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2011-03-23 18:35:06 Automatic flush during beforeCompletion(): disabled
2011-03-23 18:35:06 Automatic session close at end of transaction: disabled
2011-03-23 18:35:06 JDBC batch size: 15
2011-03-23 18:35:06 JDBC batch updates for versioned data: disabled
2011-03-23 18:35:06 Scrollable result sets: enabled
2011-03-23 18:35:06 JDBC3 getGeneratedKeys(): enabled
2011-03-23 18:35:06 Connection release mode: auto
2011-03-23 18:35:06 Maximum outer join fetch depth: 2
2011-03-23 18:35:06 Default batch fetch size: 1
2011-03-23 18:35:06 Generate SQL with comments: disabled
2011-03-23 18:35:06 Order SQL updates by primary key: disabled
2011-03-23 18:35:06 Order SQL inserts for batching: disabled
2011-03-23 18:35:06 Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2011-03-23 18:35:06 Using ASTQueryTranslatorFactory
2011-03-23 18:35:06 Query language substitutions: {}
2011-03-23 18:35:06 JPA-QL strict compliance: disabled
2011-03-23 18:35:06 Second-level cache: enabled
2011-03-23 18:35:06 Query cache: disabled
2011-03-23 18:35:06 Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
2011-03-23 18:35:06 Optimize cache for minimal puts: disabled
2011-03-23 18:35:06 Structured second-level cache entries: disabled
2011-03-23 18:35:06 Echoing all SQL to stdout
2011-03-23 18:35:06 Statistics: disabled
2011-03-23 18:35:06 Deleted entity synthetic identifier rollback: disabled
2011-03-23 18:35:06 Default entity-mode: pojo
2011-03-23 18:35:06 Named query checking : enabled
2011-03-23 18:35:06 building session factory
2011-03-23 18:35:06 Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into student (sname, sid) values (?, ?)
2011-03-23 18:35:07 SQL Error: 1366, SQLState: HY000
2011-03-23 18:35:07 Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'sname' at row 1
2011-03-23 18:35:07 Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.test.addStudent.main(addStudent.java:25)
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'sname' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.test.addStudent.main(addStudent.java:25)
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'sname' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
高手解决下。。。烦扰我几天了。
2011年3月23日 18:38