我正在向数据库中添加信息,并且当我想在PreparedStatement(stmt)上设置时间戳(d2)时,日期的小时数将减少2小时。查看代码和输出: Connection con = null; PreparedStatement stmt = null; try { con = ds.getConnection(); stmt = con.prepareStatement("INSERT INTO "+machines.get(0)+ "("+Information.variables.get(0)+","+Information.variables.get(1)+","+Information.variables.get(2)+ ","+Information.variables.get(3)+","+Information.variables.get(4)+","+Information.variables.get(5)+","+Information.variables.get(6)+","+Information.variables.get(7)+","+Information.variables.get(8)+ ","+Information.variables.get(9)+","+Information.variables.get(10)+","+Information.variables.get(11)+") VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); String s = info.Data(); Date d = transformStringToDate(s); System.out.println(d); java.sql.Timestamp d2 = new java.sql.Timestamp(d.getTime()); stmt.setTimestamp(1, d2); System.out.println(d2); stmt.setDouble(2, info.Pes_programat()); stmt.setDouble(3, info.Pes_real()); stmt.setDouble(4, info.Pes_maxim()); stmt.setDouble(5, info.Pes_minim()); stmt.setInt(6, info.Marxa()); stmt.setDouble(7, info.Incidencia()); stmt.setDouble(8, info.Contador_de_coixins()); stmt.setDouble(9, info.Producte()); stmt.setDouble(10, info.Fibra()); stmt.setDouble(11, info.Pes_funda()); stmt.setDouble(12, info.Mides_funda()); System.out.println(stmt); 这是System.out.println()的输出:2018年6月15日星期五18:55:53 CEST2018-06-15 18:55:53.0com.mysql.cj.jdbc.ClientPreparedStatement:INSERT INTO m1(Data,Pes_programat,Pes_real,Pes_maxim,Pes_minim,Marxa,Incidencia,Contador_de_coixins,Producte,Fibra,Pes_funda,Mides_funda)值55('2018-06-15 53.0',211.0、11.98、2.15、1.85、1、0.0、151.0、1.0、2.0、50.0、190.0)第一个日期类型Date是正确的,也是Timestamp d2变量。但是,当我调用stmt.setTimestamp时,将小时数减为2。
添加回答
举报
0/150
提交
取消