Dear All,
I have one doubt for how to insert the java.sql.Date into ms-sql server.
I tried the below code but it couldn''t be inserted. I did wrong in
my code that is ps.setDate(1,full_date_time) to ps.setString(1,full_date_time);
How can i covert the String(full_date_time) to java.sql.Date() and insert the MM/DD/YYYY format in ms-sql database?
I set datetime as datatype in my products table.
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
Date d=new Date();
String full_date_time=sdf.format(d).trim();
out.println("Date--------"+full_date_time);
ps = con.prepareStatement("insert into products values(?)");
ps.setDate(1,product_id);
ps.executeUpdate();
%>
thanks in advance
V. Prasath.
解决方案
Dear All,
I have one doubt for how to insert the java.sql.Date into ms-sql server.
I tried the below code but it couldn''t be inserted. I did wrong in
my code that is ps.setDate(1,full_date_time) to ps.setString(1,full_date_time);
How can i covert the String(full_date_time) to java.sql.Date() and insert the MM/DD/YYYY format in ms-sql database?
I set datetime as datatype in my products table.
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
Date d=new Date();
String full_date_time=sdf.format(d).trim();
out.println("Date--------"+full_date_time);
ps = con.prepareStatement("insert into products values(?)");
ps.setInt(1,product_id);
ps.executeUpdate();
%>
thanks in advance
V. Prasath.
What error message did you get ?
What error message did you get ?
I wrongly typed in ps.setDate(1,date_of_insert); instead of
ps.setInt(1,date_of_insert);
so please pardon me.
when i compile that coding it throws the followin error......
Incompatible type for method. Can''t convert java.lang.String to java.sql.Date.
ps.setDate(1,date_of_insert);
I wrongly typed in ps.setDate(1,date_of_insert); instead of
ps.setInt(1,date_of_insert);
so please pardon me.
when i compile that coding it throws the followin error......
Incompatible type for method. Can''t convert java.lang.String to java.sql.Date.
ps.setDate(1,date_of_insert);
To convert the String to sql Date, you use Date.valueOf (string). The string must be in the format yyyy-mm-dd