转:http://blog.csdn.net/educast/article/details/45582497
我是用的mybatis,同样适用
使用hibernate开发程序的时候,有的时间字段没有必要填写,但是,以后hibernate查询的时候会报出
“java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp”
的错误, 这是因为hibernate认为这个不是一个有效的时间字串。
而有效的日期格式为“ 0001-01-01 00:00:00.0 ”
查看了mysql5的帮助文档对于datetime的解释如下
Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented 关于所有Datetime类型由0组成的数据,这些值不能在java中被可靠的表示
reliably in Java.
Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.
当这些值正在从ResultSet容器中读取时候,Connector/J 3.0.x 一直把他们转换为NULL值。
Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards.
依照JDBC和SQL的标准这些值碰到的最正确的处理方式就是在缺省情况下产生异常
This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:
JDBC允许用下列的值对zeroDateTimeBehavior 属性来设置这些处理方式,
exception (the default), which throws an SQLException with an SQLState of S1009.
设置为exception 异常(缺省)用一个SQLState的s1009错误号来抛出一个异常
convertToNull, which returns NULL instead of the date.
设置为convertToNull,用NULL值来代替这个日期类型
round, which rounds the date to the nearest closest value which is 0001-01-01.
设置为round,则围绕这个日期最接近的值(0001-01-01)来代替
修改你的jdbc连接
jdbc:mysql://localhost/schoolmis?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
分享到:
相关推荐
异常:Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp (2011-05-25 11:38:40) 描述:非空无默认值的Datetime类型字段,查询时程序报以下错误: Value ‘0000-00-00 00:00:00’ can ...
The speech signal for the particular isolated word can be viewed as the one generated using the sequential generating probabilistic model known as hidden Markov model (HMM). Consider there are n ...
Earlier versions of Delphi and C++ Builder will not be supported. If you need Delphi 3 or C++ Builder 3 support you will have to revert to version 3.7 of the Drag and Drop Component Suite. The ...
Contents Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 ... It should be pointed out that SQL Server was linked using the /LAREGEADDRESSAWARE flag and can leverage ...
The features can be of any type and in any number of dimensions, and are defined by the user. The EMD is defined as the minimum amount of work needed to change one signature into the other. The ...
To create complex objects, primitives can be used as “tools” to cut holes, carve away, or join. The operations that are performed with these “tools” are often referred to as Boolean operations. ...
Other assets can be represented as user assets or resources: A user asset is an entity that is conceptually part of another entity and so owned by that entity. It is therefore automatically copied ...
DefaultTableCellRenderer recognizes a few primitive types, rendering them as strings, and can even display Boolean types as checkboxes. But it defaults to displaying the value returned by toString() ...
How can we apply machine learning to data that is represented as a sequence of observations over time? For instance, we might be interested in discovering the sequence of words that someone spoke ...
value represented by the name/value pair that should be serialized, or undefined if nothing should be serialized. The toJSON method will be passed the key associated with the value, and this will ...
can send SQL expressions on the server through the corresponding access engine. It is TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh component. There are a ...
can send SQL expressions on the server through the corresponding access engine. It is TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh component. There are a ...
When we first began developing OpenShift in Action, it was going to be a book focusing on the ops side of DevOps in OpenShift. Existing books focus on OpenShift’s devel- oper experience, and we ...
within windows, and resources, such as documents, are represented by graphical icons. User controls are packed into hierarchical drop-down menus, buttons, sliders, etc. The user manipulates the ...
Multilevel layout of column titles - fields of dataset record can be represented as several rows in the grid to enhance the display of information to end-users at runtime. Column layout can be easily...
While adapters (also known as Network Interface Cards, or NICs) do play a significant role in implementing link-layer functions, they do not encompass all services; some are implemented in software. ...
This project model is not meant to be a tool to justify creating impositions for developers, but as a tool to facilitate coordination. It is meant as a description of the project, with an overview of...
As you can see,indexers behave much like a custom collection supporting the IEnumeratorand IEnumerableinterfaces in that they provide access to a container’s subitems. The major difference ofcourse ...
2. **Why `new` isn't Quite so Awful**: Explains scenarios where using `new` can be beneficial, such as for creating objects with specific constructors. 3. **Why You Should Use Prototypes**: Argues for...