- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我是新手。我试图将两个日期字段插入 Mysql .PFB//DAO类方法添加字段。所有字段均来自jsp表单。
public boolean addIssue(Connection conn, IssueDTO dto)throws ParseException{
String startDate=dto.getStartDate();
String endDate=dto.getStartDate();
System.out.println("the start date from dto--"+dto.getStartDate());
System.out.println("The end date from dto"+dto.getEndDate());
DateFormat format=new SimpleDateFormat("MM/dd/yyyy");
Date newStartDate=format.parse(startDate);
Date newEndDate=format.parse(endDate);
try{
String sql="INSERT INTO issue_description (issue,keyword,applicationName,objectName,teamName,startDate,endDate,resolution,priority) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement statement=conn.prepareStatement(sql);
statement.setString(1, ""+dto.getIssue());
statement.setString(2, ""+dto.getKeyword());
statement.setString(3, ""+dto.getApplicationName());
statement.setString(4, ""+dto.getObjectName());
statement.setString(5, ""+dto.getTeamName());
statement.setString(6, ""+newStartDate);
statement.setString(7, ""+newEndDate);
statement.setString(8, ""+dto.getResolution());
statement.setString(9, ""+dto.getPriority());
statement.executeUpdate();
下面是错误日志:::前四行是来自各个阶段检查的jsp的日期值。但是在插入数据库时,其更改为“Wed Oct 14 00:00:00 IST 2015”。请建议这里发生了什么。
10/14/2015
10/14/2015
the start date fr om dto--10/14/2015
The end date from dto10/14/2015
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'Wed Oct 14 00:00:00 IST 2015' for column 'startDate' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2983)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at com.sm.dao.IssueDAO.addIssue(IssueDAO.java:65)
at com.controllers.AddIssueController.doPost(AddIssueController.java:72)
最佳答案
这是因为 newStartDate
和 newEndDate
是 Date
对象,并且每当您将任何 java 对象与 String< 连接时
,java将调用对象的toString()
方法来获取对象的字符串表示形式。
这是您的犯罪方代码:
statement.setString(6, ""+newStartDate);
statement.setString(7, ""+newEndDate);
这是Date.toString()
的格式:
Converts this Date object to a String of the form:
dow mon dd hh:mm:ss zzz yyyy
where:
•dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
•mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
•dd is the day of the month (01 through 31), as two decimal digits.
•hh is the hour of the day (00 through 23), as two decimal digits.
•mm is the minute within the hour (00 through 59), as two decimal digits.
•ss is the second within the minute (00 through 61, as two decimal digits.
•zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
•yyyy is the year, as four decimal digits.
我不会将日期字符串转换为对象。相反,我的 SQL 查询将具有格式为 %d/%m/%Y
的 STR_TO_DATE
函数,并让 MySQL 进行日期格式化。
关于java - 数据截断:Incorrect value: error while inserting Date field to Mysql DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33112054/
我正在使用带有 64 位插件的 64 位操作系统 Windows 7 终极机器 VS2008。 我已经在 32 位和 64 位、调试和发布配置中成功构建了我的项目。64 位调试未启动;它给出了错误:
我遇到了一个我不理解的 java 泛型编译时错误。 我有两种方法: public static final T doStuff(List list, int k, Comparator compar
在下面的类(class)中,我尝试打印工资系统中员工的详细信息。请注意,Porter、Pharmacist 和 Surgeon 均继承自 Employee。 但是,它只是重复打印添加到数组中的第一个员
package chapter5; import java.util.Scanner; public class Exercise5 { public static void main(Str
WITH list_dedup (Company, duplicate_count) AS ( SELECT *, ROW_NUMBER() OVER (
我有一些 base64 编码的数据,即使其中存在填充错误,我也想将其转换回二进制。如果我使用 base64.decodestring(b64_string) 它会引发“不正确的填充”错误。还有其他方法
我正在致力于将大型 Delphi 代码库调整为 64 位。在许多情况下,有些行将指针转换为 32 位值或从 32 位值转换为类似于以下内容的行: var p1,p2 : pointer; begi
我正在尝试在 rtaudio 中生成一个简单的正弦波,以验证我了解发生了什么。但是,结果是错误的。 我有一个全局float timec ,以及使用 openStream 调用的回调它应该用样本填充缓冲
将我们的 Jenkins 主安装更新到最新的 LTS 版本 2.46.3 后,其从属设备之一(Windows 7 计算机,32 位)无法与主设备连接。 我们收到的错误是: java -jar slav
实现ROCR曲线,kNN,K进行10倍交叉验证。 我正在使用电离层数据集。 这是属性信息,供您引用: -如上所述,所有34个都是连续的 -根据定义,第35个属性为“好”或“坏” 以上总结。这是一个二进
我正在阅读有关“Servlet 3.0 中的异步处理支持”的专家(?)教程(http://www.javaworld.com/javaworld/jw-02-2009/jw-02-servlet3.h
我目前正在为我即将开展的项目制作自己的关卡创建器(图 block map )。一切都很顺利,只是当我添加放大和缩小选项时遇到了问题。我有一个类正在处理当前的所有输入和渲染,因为我刚刚开始。 Level
我在 Eclipse mars 2.0 中使用 Mockito(1.10.19) 进行 Java EE 测试来测试离线存储库。此类依赖于 InitialData 类来检索信息。 我的第一个任务是将地址
我正在尝试实现“算法简介”一书中所述的合并排序算法。尽管实现是按照书中指定的,但输出不正确。很有可能出现相差一的错误,但我无法指出它。有什么指点吗? #include #include #defi
我正在尝试确定 Windows 任务栏(系统托盘?)停靠在哪一侧 - 这样我就可以将弹出窗口定位在任务栏的上方/下方/左侧/右侧。 我正在使用 SHAppBarMessage(ABM_QUERYPOS
我正在使用以下公式实现 DCT 变换: 但是结果不正确。对于一些 8 × 8 矩阵, 0 0 0 0 0 0 0 0 210 210 210 210 210 210 21
我正在尝试编写将内存流转换为 png 图像的代码,但在 using(Image img = Image.从流(毫秒))。它没有进一步指定它,所以我不知道为什么会收到错误以及我应该怎么做。 此外,如何将
这个语句工作正常: SELECT * FROM table_name WHERE DATE(date_event) < DATE(NOW() - INTERVAL 90 DAY); 在 DELETE
当我删除图像并尝试保存配置文件时,它显示错误“incorect padding” 我的代码是 模型.py import webcam.admin from webcam import widgets
我正在尝试创建一个函数来计算两个字符串之间的汉明距离。当我调用这个函数时,它应该告诉我两个字符串之间不匹配的字符数。 我的输出不正确。我不断得到随机数结果。下面是我的代码: using namespa
我是一名优秀的程序员,十分优秀!