How to insert date object of java into SQL server......

I have to insert date object into SQL server....For which i have created date object Date date=new Date(); After this i m exeute SQL insert operation insert into table_name values("+date+"); It is giving exceptionsCan anybody help me?
[290 byte] By [Anurag_Tripathia] at [2007-11-26 15:35:36]
# 1
You need two things: java.sql.Date (not java.util.Date) and a PreparedStatement. Never concatenate queries like this.
CeciNEstPasUnProgrammeura at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Oh, and not that it matters this time, but generally, wise people add the error message to their posts.
CeciNEstPasUnProgrammeura at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Ya i know SQL injection but i was just taking an exampleany solution of above mentioned problem?
Anurag_Tripathia at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
> Ya i know SQL injection but i was just taking an> example> any solution of above mentioned problem?I thought I told you what to do. <_<
CeciNEstPasUnProgrammeura at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Is it solved?If its not working despite of the answers given by our friends, try giving a single quote.... try something like this...."insert into tablename values( ' "+date+"')";
Vigitha at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
if u want system date -"Insert Into TableName valuese (Sysdate)"Or if u have some other date stored in variable, u will ve to provide date forMat .
Anuj_Sinhaa at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Use "PreparedStatement":

// ...

String updateSQL = "UPDATE User SET userCreatedDate=? WHERE userId=?";

PreparedStatement stmt = conn.prepareStatement(updateSQL);

date = new java.util.Date();

stmt.setDate(

1,

new java.sql.Date(

date.getYear(),

date.getMonth(),

date.getDay()));

stmt.setString(2,userId);

int updatedRowCount = stmt.executeUpdate();

// ...

by Avatar Ng

[my blog http://avatar21.superihost.com/]

Avatar_Nga at 2007-7-8 21:53:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...