Convert String to sql date

hi all,
i have a date in string format Tue, 06 Feb 2007 12:38:17 GMT
How do i convert it to sql datetime.
Date date = new Date("Tue, 06 Feb 2007 12:38:17 GMT");// creating date
          java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                    "yyyy-MM-dd HH:mm:ss");// format definition
          java.sql.Time pubDate = java.sql.Time.valueOf(sdf.format(date));
          System.out.println(pubDate);This code gives me java.lang.NumberFormatException.
Thanks in advance.......
VikraM

is "EEE d MMM yyyy HH:mm:ss Z" your default data format
if not your first constructor will not parse date properly so your date object contains invalid date, when you try to format it it throws exception.
check it
sudhir nimavat

Similar Messages

  • JTextfield input Date convert to java.sql.Date

    Hi. I have a textfield for users to input date in 'dd/mm/yyyy' format and I would like to format this input into java.sql.Date to be stored into a database. How should I go about doing that ?
    I did the following:
    SimpleDateFormat formatDate = new SimpleDateFormat("dd/mm/yyyy");
    java.util.Date invoiceDate = formatDate.parse(jTextField3.getText());
    java.sql.Date sqlDate = new java.sql.Date(invoiceDate.getTime());and when I input into jTextField3 the value '28/05/2008' , I found in my database '2008-01-28'. January and May is a few months off and is totally not what I wanted.

    Hi you did you code perfect, but you need to change the pattern for formatting the Date
    dd - date
    mm - minute
    yyyy - year
    here you are parsing month as minute, so the output may wrong..!
    If you need to format properly
    please use the below pattern
    {color:#0000ff}SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");{color}

  • Convert Data type from Oracle Data time string to SQL Date time data type

    I have a time stamp column pulled from oracle into a SQL server db table varchar datatype column.
    Now i want to change that column to date time.
    Following is the data present in the table:
    01-APR-11 02.15.00.026000 AM -08:00
    01-APR-11 04.15.00.399000 AM -08:00
    01-APR-11 06.15.00.039000 AM -08:00
    I want to convert this data into sql server datetime data type.
    Please advice.
    Thanks,
    Sam.
    I am unable to find the solution in other sites which is why I have posted it in Oracle forum for seeking solution.
    Thanks in Advance.
    Sam.

    Sam,
    How are you actually loading the data into SQL*Server - are you using something like an Oracle gateway, BCP or another Microsoft utility of some sort ?
    If you are using an Oracle problem then we may be able to help but if using a Microsoft utility then you should really follow up with Microsoft to know what format the data should be in to use a Microsoft utility.
    Regards,
    Mike

  • Converting string to util date

    I have a method to define if a string value can be converted into date.
    When I pass "20080815" value as a parameter it works fine. But when I pass "20082415" value it also converts the value to a date where the value should not be converted to date. At least I expect so. It should throw an exception because month can not be 24.
    Why an how could it be? And is there another way to solve the situation?
        public static int ToDate(String p_value) {
            try {
                DateFormat df = new SimpleDateFormat("yyyyMMdd");
                date_val = df.parse(p_value);
                return 1;
            catch(Exception e) {
                return -1;
        }Edited by: kalyon on Sep 4, 2008 3:50 AM
    Edited by: kalyon on Sep 4, 2008 3:50 AM

    df.setLenient(false);read the API docs.

  • Convert string to a date

    Gurus,
    It would be highly appreciable if you could help me in knowing how to convert a string to date in obiee. I know we need to use CAST function. I don't have enough material to figure it out myself.
    Awaiting a reply.
    Thanks.

    Nico - Thanks for the link, this is very helpful. Please tell me what's wrong in the following code. Am enlcosing the code and the error.
    Code 1 :
    CAST(CAST('31-OCT-'||CAST(YEAR("Dim - MBS Loan"."CLOSING DATE") AS CHAR) AS CHAR) AS DATE)
    Error 1:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 25137, message: ORA-25137: Data value out of range at OCI call OCIStmtExecute: select distinct D1.c1 as c1, D1.c2 as c2, D1.c3 as c3,
    Code 2 :
    CAST('31-OCT-'||SUBSTRING(CAST(YEAR("Dim - MBS Loan"."CLOSING DATE") AS CHAR),3,2) AS DATE)
    Error 2:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1840, message: ORA-01840: input value not long enough for date format at OCI call OCIStmtExecute: select distinct D1.c1 as c1, D1.c2 as

  • How to convert string value to date

    hi,
    in my application user enters the date in dd/MM/yyyy formatt..before submtiing to some external server i haveto formatt it to MM/dd/yyyy format bcos it accepts olny this formatt.when i retrieve the string date in my jsp using Sring date = req.getParameter();
    i want to convert this date to MM/dd/yyyyy formatt.
    Regards,

    Sring date = req.getParameter();
    string formatted = date.substring(0,3) + "/" + date.substring....
    ?

  • Convert string to fomated date

    I have a string type "dd/mm/yyyy", how can i convert it to "MMMddyyyy hh::mm:ss AM/PM" date format ??

    Calendar cal0 = Calendar.getInstance(); // today's date
                   SimpleDateFormat dateFormat = new SimpleDateFormat("MMMddyyyy hh::mm:ss AM/PM");          
                                                      cal0.add(Calendar.DATE,-0);
                                                      Calendar calx=cal0.getInstance();
              String date0 = dateFormat.format(cal0.getTime());
                                                                                                        System.out.println("Date "+date0);
    use this,.
    if there is any problem write it again,
    bye,
    Samir

  • How can I convert the encrypted SQL data to clear text in CCM?

    I want to retrieve CCM information from SQL database but many of them display as encrypted as follows,
    {14AE763F-D1EE-44A2-93C1-00FB95578E43} {7FD1AACD-6E85-4B79-A0D1-5F25074414D0}
    Any way to convert to clear text?
    Thanks in advance,

    I need to summarize the current CCM configuration into spreadsheet and want to reduce the labor work by manually typing. For example, the Route List display in SQL as I mentioned instead of clear text.
    Any tool available to get all the configuration information as clear text?
    Thanks,

  • How to convert JAVA.SQL.DATE date in YYYY/MM/DD format into DD/MM/YYYY

    i am using informix database which accepts date value in the form of DATE format......
    the other part of my application takes date from the field in DD/MM/YYYY format...so i have to convert my java.sql.date in YYYY/MM/DD fromat into DD/MM/YYYY fromat of same type before inserting into db......
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........

    816399 wrote:
    i am using informix database which accepts date value in the form of DATE format......Huh?
    Maybe you mean Informix (fronted by JDBC) expects date values as java.sql.Date objects?
    the other part of my application takes date from the field in DD/MM/YYYY format...
    so i have to convert my java.sql.date in YYYY/MM/DD format into DD/MM/YYYY format of same type before inserting into db......I am not sure why you are talking about formats here.
    There is no formatting inherent in a java.util.Date object
    nor in a java.sql.Date object.
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........You can easily create a java.sql.Date object from a java.util.Date object.
    String s = "31/12/2010";
    java.util.Date ud = new java.text.SimpleDateFormat("dd/MM/yyyy").parse(s);
    java.sql.Date sd = new java.sql.Date(ud.getTime());
    ud = sd; // java.sql.Date extends java.util.Date so no conversion is needed

  • Convert java.sql.Date to oracle.jbo.domain.Date in oaf

    Hi,
    Need to dafault NeedBydate(i get in from query as below) to a messagelovinput and make it read only.
    i am facing some issue in converting from java.sql.Date to oracle.jbo.domain.Date.
    unable to figure out the problem.
    below is the sample code im trying to use.
    PreparedStatement ps=pageContext.createPreparedStatement("select sysdate from dual");
    ResultSet rs=ps.executeQuery();
    if (rs!=null && ps.next()
    java.sql.Date sqlDate= rs.getDate(1);
    oracle.jbo.domain.Date oracleDate = new oracle.jbo.domain.Date(sqlDate.getTime());
    vorow.setAttribute("Datevalue",oracleDate);
    this is my assumption : to set to UI i need date in format dd-Mon-yyyy.(am i correct? as to get that format i tried to use simple date format class but no use)
    when i tried to use simple date format :unpaseable date exception was raised.
    please guide.

    Hi,
    Why are you using this code???
    PreparedStatement ps=pageContext.createPreparedStatement("select sysdate from dual");
    ResultSet rs=ps.executeQuery();
    if (rs!=null && ps.next()
    java.sql.Date sqlDate= rs.getDate(1);
    oracle.jbo.domain.Date oracleDate = new oracle.jbo.domain.Date(sqlDate.getTime());
    you can get sysdate using this and then set it
    oracle.jbo.domain.Date currentDate = am.getOADBTransaction().getCurrentUserDate();
    java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("yyyy-MM-dd");
    String DateForm = displayDateFormat.format(currentDate.dateValue());
    oracle.jbo.domain.Date dateset = new oracle.jbo.domain.Date(DateForm);
    and then set the attribute
    vorow.setAttribute("Datevalue",dateset);
    Thanks,
    Gaurav

  • Convert java.sql.Date to java.util.Date

    How do i convert a java.sql.Date to java.util.Date ?
    SimpleDateFormat formatter = new SimpleDateFormat ("dd/MM/yy HH:mm");
    Date received=myresultset.getDate(1);
    String utildate = formatter.format(received);
    <%=utildate%>
    Result : doesn't keep the HH:mm format
    14/03/04 00:00
    Ideas ?

    There is simple way to do this job...
    java.util.Date utilDate = new java.util.Date();
    java.sql.Data sqlDate = new java.sql.Date(utilDate.getTime())
    Enjoy Coding ! ! ! ! !

  • Currency to string with sql

    hi,
    i want to insert, update records which have money data type fields
    and select records from db.
    how can � convert string to money data type (in Ms SqlServer-2000) for insert, update.
    And also how can i convert money datatype to string for select sql sentences.
    thanks for your interests.

    Hi incihan,
    The corresponding data type in Java for MS SQL Server's money is javax.sql.BigDecimal
    I hope it will help u.
    regards,
    Humayun.

  • Please Help with sql.Date problem

    I have spent alot of time on what I thought would be an otherwise simple task, and I beleive I am close to completion but I need some much needed help. I have posted various forms of my code to try and acheive the solution but the responses received have been limited.
    I am trying to delete a record from a MS Access database where a Date/Time field in the database (Err_Date) equals a date entered by the user via a textbox.
    I finally have gotten the correct record to delete from the database, but what is very strange is that Tomcat is throwing a 'java.lang.NullPointerException' error. Then when I re-open the database the correct record is deleted.
    Here is my code:
    <%@page import="java.sql.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%@ page import="java.util.Date"%>
    <%
    Connection con = null;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:errorlog", "admin", "");
    catch(Exception e){
         out.println(e.getMessage());
    ResultSet rs=null;
    Statement stmt=null;
    try {
    stmt=con.createStatement();
    String end = request.getParameter("To");//FROM TEXTBOX
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat ("dd/MM/yyyy");
    java.util.Date d2 = df.parse(end);//CONVERT STRING TO UTIL DATE
    java.sql.Date date2 = new java.sql.Date(d2.getTime());//CONVERT TO SQL
    PreparedStatement stmnt = con.prepareStatement("DELETE FROM tblError WHERE Err_Date = ?");
    stmnt.setDate(1, date2);
    stmnt.executeUpdate();
    stmnt.close();          
    //CLOSE RESULT SET          
    rs.close();
         stmt.close();
    con.close();
    //CATCH EXCEPTIONS
    catch (SQLException e) {
         out.println(e.getMessage());
    %>

    well, in case anyone ever runs into a problem this stupid again the solution is as follows.
    the code to:
    1. retrieve date from text box
    2. covert string into util date
    3. convert util date into sql date
    4. delete from database
    is all correct.
    the problem is that I previously used String sql="SOME SQL DELETE" and then executed the result set, which of course I then had to close. This wasn't working so I switched to a Prepared Statement. I forgot to remove the 'rs.close()' statement in my code. So Tomcat was trying to close a result set that was never opened...

  • Conversions between java.util.Date, java.util.Timestamp and java.sql dates

    I am coding a hoilday booking system using JSP to interact with a SQL Server database. On my JSP form which retrieves the information I have a little javascript pop-up date selector which appears to be returning a Timestamp value although the string value is visable in the entry field. Can I pass this to a javabean as a Timestamp, so far I have only passed strings? Also I then have to enter it in the database and so will need to convert it to an sql date type but I dont know which one is best. Previous to using the Timestamp returning calendar I was just entering text and parsing it to a util.Date in the bean and then converting that to an sql.Date for entry in the database. That worked fine but I want to use the pop-up any ideas? Also my bean won't compile if I declare java.util.Timestamp t;(cannot resolve symbol Timestamp !) even though I have imported util.

    First of all, java.util.Timestamp does not exist. You probably need java.sql.Timestamp.
    java.sql.Date and java.sql.Timestamp inherit from java.util.Date. So converting from java.sql.Date or java.sql.Timestamp to java.util.Date is easy, you don't have to do anything.
    To convert a java.util.Date to a java.sql.Timestamp, do something like this:
    import java.sql.Timestamp;
    import java.util.Date;
    Date date = new Date();
    Timestamp ts = new Timestamp(date.getTime());Jesper

  • Creating SQL Date from DD/MM/YYYY request parameters

    G'day,
    I have question regarding creating SQL Date so that it can inserted into MySQL database. In my JSP screen I have two drop downs boxes (One for day and one for month) and a textbox for year.
    In my servlet I want to make a SQL date object so that I can insert it into the database. Right now what I do is create GregorianCalendar object by passing year, month and day integers. Then I create java.util.Date object using GregorianCalendar's getTime method. Finally I create SQL Date object by using java.util.Date's getTime method.
    Iam having problems using this method. When the date gets inserted in the database the month is one more then it should be. (e.g instead of date as being 20/10/1973 it will be 20/11/1973).
    What is a better way to create SQL Date object?
    btw, Iam using PreparedStatement's setDate method that is why I want to create SQL Date object.
    Thanks for your help!

    Another way is to use the SimpleDateFormat class to convert that String to a Date object, and then convert that to SQL date the same way you already do. That has the advantage that you don't have to put in all that logic you already have (right?) to check that the month is between 1 and 12, and that the day is between 1 and whatever depending on the month...

Maybe you are looking for

  • Weblogic 10.3.2 visitor entitlements roles issue

    1)I am upgrading my weblogic portal application from Weblogic 8.1SP4 to Weblogic 10.3.2 version. I found that roles that created under visitor entitlements thru weblogic portal administration portal are not visible to assigned user.For example I crea

  • Oracle not starting up:: windows:9208

    Hello all, i have a 9205 db on win 2000. i wanted to upgrade it to 9208. But after the upgradation of binaries, 'am unable to bring up the db. Seems like some problem with the service. C:\Documents and Settings\Administrator>sqlplus SQL*Plus: Release

  • Using fax viewer to open a jpeg image embedded as a link.

    Hi, In my application, I have a functionality for uploading scanned document which are in jpeg/bmp format. The user can later on see/print these documents. I am using <a target="_blank" href="">to open the document, so a new window(in case of interne

  • Equium A60 can not recognise audio CDs

    Despite having no problem playing DVDs or CD-ROMs my Equium A60 laptop won't recognise audio CDs. In fact if I look in the D drive folder it doesn't even recognise anything as being there. Recently I have had problems loading CDs into iTunes etc: the

  • Aperture, the aebs and the time capsule feature - multiple machines?

    Hi folks, The main aperture library and photos are located on my macpro which is downstairs. I load photographs into AP exclusively through this machine. I also manage the AP library from the MP as well. However, I'm thinking about putting the AP lib