代码:
public void orderSave(Order order) {
Connection conn = null;
PreparedStatement pstmt = null;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddmmss");
Date date = new Date(System.currentTimeMillis());
String sid = format.format(date);
int id = Integer.parseInt(sid);
try {
conn = DB.getConn();
String sql = "insert into salesorder values (?, ?, ?, ?, ?, ?)";
pstmt = DB.getPstmt(conn, sql);
pstmt.setInt(1, id);
pstmt.setInt(2, order.getUser().getId());
pstmt.setString(3, order.getAddr());
pstmt.setTimestamp(4, order.getODate());
pstmt.setDouble(5, order.getStatus());
pstmt.setDouble(6, order.getTotalprice());
pstmt.executeUpdate();
} catch(SQLException e) {
e.printStackTrace();
} finally {
DB.close(conn);
DB.close(pstmt);
}
}
Mysql数据库结构
+------------+---------------+------+-----+---------+-
| Field | Type | Null | Key | Default |
+------------+---------------+------+-----+---------+-
| id | int(18) | NO | PRI | 0 |
| userid | int(11) | YES | | NULL |
| addr | varchar(255) | YES | | NULL |
| odate | datetime | YES | | NULL |
| status | int(11) | YES | | NULL |
| totalprice | decimal(18,2) | YES | | NULL |
+------------+---------------+------+-----+---------+-每次提交前后台总是报
java.lang.NumberFormatException: For input string: "201005040119"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
我觉得我已经将他转化成int了,为什么还For input string: "201005040119"
麻烦大家了!!谢谢!!
public void orderSave(Order order) {
Connection conn = null;
PreparedStatement pstmt = null;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddmmss");
Date date = new Date(System.currentTimeMillis());
String sid = format.format(date);
int id = Integer.parseInt(sid);
try {
conn = DB.getConn();
String sql = "insert into salesorder values (?, ?, ?, ?, ?, ?)";
pstmt = DB.getPstmt(conn, sql);
pstmt.setInt(1, id);
pstmt.setInt(2, order.getUser().getId());
pstmt.setString(3, order.getAddr());
pstmt.setTimestamp(4, order.getODate());
pstmt.setDouble(5, order.getStatus());
pstmt.setDouble(6, order.getTotalprice());
pstmt.executeUpdate();
} catch(SQLException e) {
e.printStackTrace();
} finally {
DB.close(conn);
DB.close(pstmt);
}
}
Mysql数据库结构
+------------+---------------+------+-----+---------+-
| Field | Type | Null | Key | Default |
+------------+---------------+------+-----+---------+-
| id | int(18) | NO | PRI | 0 |
| userid | int(11) | YES | | NULL |
| addr | varchar(255) | YES | | NULL |
| odate | datetime | YES | | NULL |
| status | int(11) | YES | | NULL |
| totalprice | decimal(18,2) | YES | | NULL |
+------------+---------------+------+-----+---------+-每次提交前后台总是报
java.lang.NumberFormatException: For input string: "201005040119"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
我觉得我已经将他转化成int了,为什么还For input string: "201005040119"
麻烦大家了!!谢谢!!
解决方案 »
- hibernate 插入空值数据性能影响
- java富客户端企业应用框架发布
- Struts+Spring+Hibernate+JTA配置问题.table or view does not exist
- ear 文件怎么发布
- JAVA版 oa 工作流应该怎么开发?
- 紧急求源!!!
- 急求各位大虾
- hibernate紧急求救!大侠们救我!
- 请问在hibernate中怎样把mysql的varbinary映射成String?
- WebLogic Application Server处于中间层,是不是作为一个服务在一台中心服务器里不停运行,然后处理客户端的请求。?
- 急求助!!!maven项目中多个配置文件问题!!!
- String st = "你不知道我在等你吗?";
其次,Java这边用long,MySQL这边int没问题的。