AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

stringhe,date e preparedstatement

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
Emma Ronco
Guest





PostPosted: Tue Oct 28, 2003 3:00 pm    Post subject: stringhe,date e preparedstatement Reply with quote



Salve a tutti;è da poco che uso i preparedStatement e quindi per me molte
cose non sono ovvie.Ho questo problema.Ho una form in cui l'utente deve
compilare diversi campi tra cui selezionare la propria data di nascita da
tre menu a tendina.
Recupero i valori dal menu a tendina e li metto in una stringa;ora dovrò
inserire questi dati in una tabella di mysql;il campo datadinascita è uno
timestamp.Ho dei problemi ad inserire la data di nascita con i
preaparedstatement.
Io faccio così:


String datanascita="1979-10-25";

prep.setTimestamp(11, java.sql.Timestamp.valueOf(datanascita));

Mi da il seguente errore:
Exception:Syntax error or access violation, message from server: "You have
an error in your SQL syntax.

Come faccio ad inserire una stringa che contiene come valore una
data,tramite un preparedStatement.setTimestamp?
Grazie a tutti in anticipo.


Back to top
The Law of Lorentz
Guest





PostPosted: Wed Oct 29, 2003 7:18 pm    Post subject: Re: stringhe,date e preparedstatement Reply with quote



Sei sicuro che il problema sia proprio sul TimeStamp?
Hai provato ad eliminare momentaneamente "prep.setTimestamp" per vedere se
l'inserimento va' a buon fine...
Eventualmente prova a postare il tuo codice.

Fammi sapere.

Ciao


"Emma Ronco" <emma.ronco (AT) esanet (DOT) it> wrote

Quote:
Salve a tutti;è da poco che uso i preparedStatement e quindi per me molte
cose non sono ovvie.Ho questo problema.Ho una form in cui l'utente deve
compilare diversi campi tra cui selezionare la propria data di nascita da
tre menu a tendina.
Recupero i valori dal menu a tendina e li metto in una stringa;ora dovrò
inserire questi dati in una tabella di mysql;il campo datadinascita è uno
timestamp.Ho dei problemi ad inserire la data di nascita con i
preaparedstatement.
Io faccio così:


String datanascita="1979-10-25";

prep.setTimestamp(11, java.sql.Timestamp.valueOf(datanascita));

Mi da il seguente errore:
Exception:Syntax error or access violation, message from server: "You
have
an error in your SQL syntax.

Come faccio ad inserire una stringa che contiene come valore una
data,tramite un preparedStatement.setTimestamp?
Grazie a tutti in anticipo.





Back to top
gnazio
Guest





PostPosted: Wed Oct 29, 2003 8:09 pm    Post subject: Re: stringhe,date e preparedstatement Reply with quote



Emma Ronco <emma.ronco (AT) esanet (DOT) it> ha scritto:
Quote:
Salve a tutti;è da poco che uso i preparedStatement e quindi
per me molte
cose non sono ovvie.Ho questo problema.Ho una form in cui
l'utente deve
compilare diversi campi tra cui selezionare la propria data di
nascita da
tre menu a tendina.
Recupero i valori dal menu a tendina e li metto in una
stringa;ora dovrò
inserire questi dati in una tabella di mysql;il campo
datadinascita è uno
timestamp.Ho dei problemi ad inserire la data di nascita con i
preaparedstatement.
Io faccio così:


String datanascita="1979-10-25";

prep.setTimestamp(11, java.sql.Timestamp.valueOf(datanascita));

Mi da il seguente errore:
Exception:Syntax error or access violation, message from
server: "You have
an error in your SQL syntax.

Come faccio ad inserire una stringa che contiene come valore una
data,tramite un preparedStatement.setTimestamp?
Grazie a tutti in anticipo.


A volte si perde un sacco di tempo per delle
stupidaggini...eppure basterebbe leggere meglio le API.
Cito da java.sql.Timestamp:
***********
valueOf

public static Timestamp valueOf(String s)

Converts a String object in JDBC timestamp escape format to a
Timestamp value.

Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
IllegalArgumentException - if the given argument does not
have the format yyyy-mm-dd hh:mm:ss.fffffffff


valueOf

public static Timestamp valueOf(String s)

Converts a String object in JDBC timestamp escape format to a
Timestamp value.

Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
IllegalArgumentException - if the given argument does not
have the format yyyy-mm-dd hh:mm:ss.fffffffff
***********

Chiaro?


Inviato da www.mynewsgate.net

Back to top
gnazio
Guest





PostPosted: Wed Oct 29, 2003 8:11 pm    Post subject: Re: stringhe,date e preparedstatement Reply with quote

Oops! Me scappato un ctrl+v di troppo!
Ripeto:

*********************
valueOf

public static Timestamp valueOf(String s)

Converts a String object in JDBC timestamp escape format to a
Timestamp value.

Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
IllegalArgumentException - if the given argument does not
have the format yyyy-mm-dd hh:mm:ss.fffffffff
*********************

Inviato da www.mynewsgate.net
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.