You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Raquepo <rr...@primeorion.com> on 2003/03/18 02:28:37 UTC

Error in Prepared Statement in my Struts Action Class

I doing an app with struts. Although my problem is not directly related to struts maybe any could help me out.

I have this prepared statement 
SQLDef.BUSEMPINFO_INSERT=
INSERT INTO busempinfo (lastupdate) VALUES (?) 

but when i use this on my Java servlet like this
pstmt = conn.prepareStatement(SQLDef.BUSEMPINFO_INSERT); 
pstmt.setString(1,fdate.format(now));
pstmt.executeUpdate(); 

i got an error an Exception type error. which just state
null. It did not go to my SQLException catch. 

what seems to be cause this null error. When i turn to the mysql client and run this insert
INSERT INTO busempinfo(lastupdate) VALUES('2003-01-01'); 

i worked fine. Please help me out anyone. Thanks... 

Re: Error in Prepared Statement in my Struts Action Class

Posted by Michał Postupalski <pl...@ncnet.pl>.
On 3/18/2003 2:57 AM, Richard Raquepo wrote:
> Datetime
> i used pstmt.setString(1,fdate.format(now));
> because it does the data does not correctly forms the correct date
> pstmt.setDate(1,now);
> will only save the date (YYYY-MM-DD) but not the
> time...

U should use pstmt.setTimestamp(1, well_formed_field ) because:

"The DATETIME type is used when you need values that contain both date 
and time information. MySQL retrieves and displays DATETIME values in 
'YYYY-MM-DD HH:MM:SS' format."

So try this way:
pstmt.setTimestamp(1,now);


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Error in Prepared Statement in my Struts Action Class

Posted by Richard Raquepo <rr...@primeorion.com>.
Datetime
i used pstmt.setString(1,fdate.format(now));
because it does the data does not correctly forms the correct date
pstmt.setDate(1,now);
will only save the date (YYYY-MM-DD) but not the
time...

----- Original Message -----
From: "Micha³ Postupalski" <pl...@ncnet.pl>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, March 18, 2003 9:37 AM
Subject: Re: Error in Prepared Statement in my Struts Action Class


> On 3/18/2003 2:28 AM, Richard Raquepo wrote:
> > I doing an app with struts. Although my problem is not directly related
to struts maybe any could help me out.
> >
> > I have this prepared statement
> > SQLDef.BUSEMPINFO_INSERT=
> > INSERT INTO busempinfo (lastupdate) VALUES (?)
> >
> > but when i use this on my Java servlet like this
> > pstmt = conn.prepareStatement(SQLDef.BUSEMPINFO_INSERT);
> > pstmt.setString(1,fdate.format(now));
> > pstmt.executeUpdate();
> >
> > i got an error an Exception type error. which just state
> > null. It did not go to my SQLException catch.
> >
> > what seems to be cause this null error. When i turn to the mysql client
and run this insert
> > INSERT INTO busempinfo(lastupdate) VALUES('2003-01-01');
> >
> > i worked fine. Please help me out anyone. Thanks...
>
> what type is lastupdate field in your DB ???
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Error in Prepared Statement in my Struts Action Class

Posted by Marc Esher <jo...@cablespeed.com>.
Hopefully your lastupdate field is a timestamp field, and so you could use
pstmt.setTimestamp(xxxxxxx) or possibly pstmt.setDate(xxxx)

-----Original Message-----
From: Micha3 Postupalski [mailto:plastic@ncnet.pl]
Sent: Monday, March 17, 2003 8:37 PM
To: Struts Users Mailing List
Subject: Re: Error in Prepared Statement in my Struts Action Class


On 3/18/2003 2:28 AM, Richard Raquepo wrote:
> I doing an app with struts. Although my problem is not directly related to
struts maybe any could help me out.
>
> I have this prepared statement
> SQLDef.BUSEMPINFO_INSERT=
> INSERT INTO busempinfo (lastupdate) VALUES (?)
>
> but when i use this on my Java servlet like this
> pstmt = conn.prepareStatement(SQLDef.BUSEMPINFO_INSERT);
> pstmt.setString(1,fdate.format(now));
> pstmt.executeUpdate();
>
> i got an error an Exception type error. which just state
> null. It did not go to my SQLException catch.
>
> what seems to be cause this null error. When i turn to the mysql client
and run this insert
> INSERT INTO busempinfo(lastupdate) VALUES('2003-01-01');
>
> i worked fine. Please help me out anyone. Thanks...

what type is lastupdate field in your DB ???




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Error in Prepared Statement in my Struts Action Class

Posted by Michał Postupalski <pl...@ncnet.pl>.
On 3/18/2003 2:28 AM, Richard Raquepo wrote:
> I doing an app with struts. Although my problem is not directly related to struts maybe any could help me out.
> 
> I have this prepared statement 
> SQLDef.BUSEMPINFO_INSERT=
> INSERT INTO busempinfo (lastupdate) VALUES (?) 
> 
> but when i use this on my Java servlet like this
> pstmt = conn.prepareStatement(SQLDef.BUSEMPINFO_INSERT); 
> pstmt.setString(1,fdate.format(now));
> pstmt.executeUpdate(); 
> 
> i got an error an Exception type error. which just state
> null. It did not go to my SQLException catch. 
> 
> what seems to be cause this null error. When i turn to the mysql client and run this insert
> INSERT INTO busempinfo(lastupdate) VALUES('2003-01-01'); 
> 
> i worked fine. Please help me out anyone. Thanks... 

what type is lastupdate field in your DB ???




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org