I have a list of Orders which has start date and end date, when i add the date, the program input the true date but when i try to import the data from SQL server, the date i get is auto minus 2 days compare to the date in the database
My code for importing data
List<Order> olist = new LinkedList<>();
String sql = "SELECT o.oId,o.caId,o.cId,o.startdate,o.enddate,o.pay,o.ohiringprice,c.cName,c.cPhone,c.cAddress,ct.tType,ct.tModel FROM Orders as o INNER JOIN Customers as c ON o.cId=c.cId INNER JOIN Cars as ca ON o.caId=ca.caId INNER JOIN CarTypes as ct ON ca.tId =ct.tId";
ResultSet rs = ConnectSQL.getPreparedStatement(sql).executeQuery();
while (rs.next()) {
Order o = new Order();
o.oId = rs.getInt("oId");
o.caId = rs.getInt("caId");
o.cId = rs.getInt("cId");
o.startdate = rs.getString("startdate");
o.enddate = rs.getString("enddate");
o.pay = rs.getString("pay");
o.ohiringprice = rs.getFloat("ohiringprice");
o.cName = rs.getString("cName");
o.cPhone = rs.getString("cPhone");
o.cAddress = rs.getString("cAddress");
o.type = rs.getString("tType");
o.model = rs.getString("tModel");
System.out.println(o.startdate);
olist.add(o);
}
return olist;
}
Here is the result for the start date
2017-06-14
2017-06-14
2017-06-14
2017-06-14
2017-06-14
2017-05-13
2017-05-13
2017-05-13
The table for Order in my SQL
create table Orders(
oId int IDENTITY(1,1) primary key,
caId int,
foreign key (caId) references Cars(caId),
cId int,
foreign key (cId) references Customers(cId),
startdate DATE not null,
enddate DATE not null,
pay nvarchar(50) not null,
ohiringprice float not null
)
The real startdate records in the database
2017-06-16
2017-06-16
2017-06-16
2017-06-16
2017-06-16
2017-05-15
2017-05-15
2017-05-15
it's also happened with the endate too
for the library i'm using sqljdbc4 and sdk1.8, SQL server version is 2014