Re: Inserting 'Dates' in database

Поиск
Список
Период
Сортировка
От Dave Cramer
Тема Re: Inserting 'Dates' in database
Дата
Msg-id 1018883032.4602.13.camel@inspiron.cramers
обсуждение исходный текст
Ответ на Inserting 'Dates' in database  (Dan McDaniel <Dan-McDaniel@smh.com>)
Список pgsql-jdbc
Dan,

Can you give me some data to input into this function to see how it
breaks ?

Dave
On Mon, 2002-04-08 at 17:58, Dan McDaniel wrote:
>
> I am writing a simple Java user interface to a simple data base in
> Postgresql.
> I have no trouble connecting through my code using the JDBC driver. I can
> get several different Resultsets back with no problem. I am having trouble
> inserting data into the database. In particular  Date data types. I get a
> message that says "Bad Date external representation".
> Here is how I am trying to solve the problem:
> I am getting a text string from the user interface and storing it in a
> String varialble called " dateInsert".
> Using a method I wrote call "convertDate()" , I am converting this date
> first to a java.util.Date object, a time object  and finally to a
> java.sql.Date object called "sqldate" which I include in the Insert
> statement.
>
> here is the code snippet for the "convertDate() method:
> <pre>
>  public java.sql.Date convertDate()
>     {
>      java.util.Date adate;
>     DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT,
> Locale.US);
> try {
>            aDate = fmt.parse(dateInsert); // dateInsert is String from
> JTextPane;
>     long time = aDate.getTime();
>     sqldate = new java.sql.Date(time);
> }
>     catch (ParseException e)
>     {
>         System.out.println(e);
>     }
>     return sqldate;
> } //end of convertDate()
> </pre>
>
> I pent allmost 18 hours trying to work this out  yesterday and have run out
> of ideas. Can anyone  suggest a direction for me?
>
> Thanks
> Dan McDaniel
> Director of Architecture and Facility Planning
> ext. 2048
> beeper 1152
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>




В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: problems with setBytes getBytes
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Timestamp Problem (index out of range)