English 中文(简体)
更新/再分配日期/外地
原标题:Update/ Retrieve /Inserting date field

我在更新数据库的一个日期方面遇到困难。 亚洲开发银行的外地类型是日期/时间。

现在,我正试图更新“R_Date”的实地名称。

Currently, I am using the SQL Expression in my jsp" UPDATE request SET request_date = "+Request_Date+" "; , But it is not accepting.

在选择发言中,我使用正常选择,试图用_或date,但不接受“DD-MMM-YYYY”格式。

因此,请你帮助我重新定位/更新/更新实地,以“DD-MMM-YYYYY”为形式。

问题回答

通常的做法是在亚洲开发银行储存一个时间序列(原文,<代码>javautil)。 日期: in Javaside and java.sql.timestamp in JDBCside is to use PreparedStatement#timestamp(

Date requestDate = getItSomehow();
Timestamp timestamp = new Timestamp(requestDate.getTime());
preparedStatement = connection.prepareStatement("UPDATE request SET request_date = ?");
preparedStatement.setTimestamp(1, timestamp);

从亚洲开发银行获得一个时间序列的通常做法是使用ResultSet#gettimestamp()<>>>>>>>。

Timestamp timestamp = resultSet.getTimestamp("request_date");
Date requestDate = timestamp; // You can just upcast.

在<代码>java.util.Date 和java.lang.String之间转换,通常使用>>>> 编码:SimpleDateFormat ::

// Convert from String to Date.
String requestDateAsString = "09-Aug-2010";
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
Date requestDate = sdf.parse(requestDateAsString);

// Convert from Date to String.
String anotherDateAsString = sdf.format(someDate);

See also:

我认为,你们应当使用MON而不是MMM。

您:

UPDATE request
SET request_date = to_date( " + Request_Date + " ,  DD-MON-YYYY )

希望你们认识到,正如你的发言(如果发言有效的话),它将更新请求表中的每一行(但我不认为这符合你的意图)。

你们需要检查你试图插入的日期格式,并尝试用适当的格式来更新方法。

http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html” rel=“nofollow noreferer” http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html。

Oracle s default format for DATE is "DD-MON-YY". If you want to retrieve date in particular format you need to use :

    TO_CHAR(<date>,  <format> )

同样,如果你需要添加/更新日期,加上非标准格式的日期,则需要使用:

TO_DATE(<string>,  <format> )

<代码><format> strings can be formation from over 40 options. 一些较为受欢迎的方面包括:

    MM  Numeric month (e.g., 07)
    MON Abbreviated month name (e.g., JUL)
    MONTH   Full month name (e.g., JULY)
    DD  Day of month (e.g., 24)
    DY  Abbreviated name of day (e.g., FRI)
    YYYY    4-digit year (e.g., 1998)
    YY  Last 2 digits of the year (e.g., 98)
    RR  Like YY, but the two digits are ``rounded   to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906
    AM (or PM)  Meridian indicator
    HH  Hour of day (1-12)
    HH24    Hour of day (0-23)
    MI  Minute (0-59)
    SS  Second (0-59)




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签