Home > Database > Mysql Tutorial > body text

java与sqlserver08日期类型转换问题

WBOY
Release: 2016-06-07 15:33:34
Original
1513 people have browsed it

我3次调用查询语句,出现3次错误, 1、date不能隐式 转换 为binary,(查询时) 2、varbinary不能转为date 3、 从字符串 转换 日期 和/或时间时, 转换 失败。 (查询时) 分享一些很好的文章: http://zhidao.baidu.com/link?url=t-7cAHd5z0FQngE5fYMieZSug

我3次调用查询语句,出现3次错误,

1、date不能隐式转换为binary,(查询时)

2、varbinary不能转为date

3、

从字符串<strong>转换</strong><strong>日期</strong>和/或时间时,<strong>转换</strong>失败。
Copy after login
(查询时)

分享一些很好的文章:

http://zhidao.baidu.com/link?url=t-7cAHd5z0FQngE5fYMieZSugMcu0zu4Mit-GpZj8N_kQouCz5NDQ17cDvXdRZOgveNdyN1bupwSsg_QlIUWUa

http://blog.knowsky.com/180534.htm

http://www.iteye.com/problems/76835

http://ganjp.iteye.com/blog/987520

对于第一种,前面已经提到解决方法,讲hibernate映射改为timestamp sql里面date转为datetime

第二种类似于第一种解决

第三种是最无语的,java里面date类型是默认英文 类型(虽然都是日期类型表示方式不一样而已,Fri Apr 11 00:00:00 CST 2014这种)。 可以转为YYYY--MM-DD HH-MM-SS 这种2014-04-11 但是注意,这是String类型! 我们查询数据库 以date为条件  通常大家应该写查询条件函数

public List find_courseBy(int Stuid,Date Cor_date,String AMPM);

hibernate生成的查询语句是:

select register0_.Cor_id as Cor1_0_, register0_.Stuid as Stuid0_, register0_.Cor_date as Cor3_0_, register0_.Zhou as Zhou0_, register0_.Week as Week0_, register0_.AMPM as AMPM0_, register0_.FirstCor as FirstCor0_, register0_.SecCor as SecCor0_, register0_.Intime as Intime0_, register0_.Outtime as Outtime0_, register0_.R_Result as R11_0_, register0_.R_Sign as R12_0_, register0_.Inpic as Inpic0_, register0_.Outpic as Outpic0_ from T_Course register0_ where register0_.Stuid='220' and register0_.Cor_date='Fri Apr 11 00:00:00 CST 2014' and register0_.AMPM='PM'
Copy after login
注意到没有是英文的类型!所以会报(但是我在数据库建立查询语句的时候  英文的日期是不能查询的,但是‘2014-4-4’这种类型却能查到,所以 我讲查询函数日期类型改为String 将日期转为String 完美查询!)
错误
Copy after login
从字符串<strong>转换</strong><strong>日期</strong>和/或时间时,<strong>转换</strong>失败   
Copy after login
register0_.Cor_date='Fri Apr 11 00:00:00 CST 2014'
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template