有没有办法在mysql表中存储以下日期
日期= 2017-01-05T00:00:00 + 05:30
//Table
create table test(dob DATETIME);
//Insert
insert into test(dob) values ('2017-01-05T00:00:00+05:30') // Throws error saying Incorrect datetime
有没有办法可以在java代码的mysql db中插入以下日期。
答案 0 :(得分:0)
如果你有Date
个对象,那就好了。否则,使用SimpleDateFormat
将字符串解析为SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
Date d = sdf.parse("2017-01-05T00:00:00+05:30");
对象,如下所示:
PreparedStatement ps = conn.prepareStatement("insert into test(dob) values (?)");
ps.setDate(1, new java.sql.Date(d.getTime()));
ps.executeUpdate();
然后你可以让PreparedStatement像这样插入日期:
newJson = open("/users/skylake/desktop/newJson.txt", "w")
with open("/users/skylake/desktop/newNodeData.txt", "r") as f:
content = f.readlines()
content =[x.strip() for x in content]
with open("/users/skylake/desktop/newNodeData2.txt", "r") as d:
dcontent = d.readlines()
dcontent =[x.strip() for x in dcontent]
#JSON format
"""{"id": , "label":}"""
for i in range(len(dcontent)):
jsonData = '{"id":', content[i] + ',', '"label":', dcontent[i]+'}'
newJson.write(jsonData)