Problem querying date fields

I am having a problem querying on date fields using the Thin driver. I originally had the problem in the context of a bean used by a JSP, but reproduced the problem in a test app. The problem is that despite the fields being populated and verifying the SQL in SQLPLUS, the calls to ResultSet.getString() and getDate() always return null.
I run the query as follows:
results = statement.executeQuery("select NAME, START_DATE from EMPLOYEES where id=1");
String startDate;
try{
results.next();
startDate = results.getString("START_DATE");
catch ...
startDate always comes up null.
I have also tried ResultSet.getDate(), same problem.
Am I doing something wrong, or is there a bug? I have searched the news groups and bug reports and haven't found anything.
Also, a possibly related problem:
Using the same driver, a where clause of the form "where START_DATE < {d `2000-01-01'}" does not return any records, despite several qualifying records in the database.
This literal date format comes from section 11.3 of the JDBC 1.2 spec. Am I using this correctly?
I am using the 8.1.6 driver, and I think the db is 8 or 8i, I will check with the DBA tomorrow.
Any help is appreciated.
Thanks,
Al

Use PreparedStatement and its set methods instead. It will not only protect you from SQL injections, but it will absolutely also ease setting Java objects in an SQL query.
Prepare here: http://www.google.com/search?q=preparedstatement+tutorial+site:sun.com

Similar Messages

  • Problem with Date fields in Search panel

    Hi all,
    I use TP2 and in my jspx page I have a search panel with two date fields and table where the results is displayed. But there is a problem with these date fields, because when I search dates the results is nothing even I retype the date from table. Also I have other pages where this problem exist with same structure.
    Could somebody help me with some advice?
    Thanks in advance!

    Hi Frank,
    Thanks for the answer.
    I use the standart method to make search panel with drag and drop the data control to the page. The other search panel fileds work fine, only the date fileds are problem. Maybe something in view object doesn't work properly.
    Here I post the code from my page.
    <table border="1" style="margin:5px;">
    <tr>
    <td>
    <af:showDetailHeader text="ТЪРСЕНЕ" disclosed="true"
    inlineStyle="width:780px;">
    <table cellspacing="2" cellpadding="3" border="0">
    <tr align="left">
    <td align="right">
    <af:outputLabel value="#{bindings.EGN.hints.label}"/>
    </td>
    <td align="left">
    <af:inputText value="#{bindings.EGN.inputValue}"
    label="#{bindings.EGN.hints.label}"
    columns="#{bindings.EGN.hints.displayWidth}"
    maximumLength="#{bindings.EGN.hints.precision}"
    simple="true"/>
    </td>
    <td align="right">
    <af:outputLabel value="#{bindings.LNC.hints.label}"/>
    </td>
    <td align="left">
    <af:inputText value="#{bindings.LNC.inputValue}"
    label="#{bindings.LNC.hints.label}"
    columns="#{bindings.LNC.hints.displayWidth}"
    maximumLength="#{bindings.LNC.hints.precision}"
    simple="true"/>
    </td>
    <td align="right">
    <af:outputLabel value="#{bindings.AccPersonID.hints.label}"/>
    </td>
    <td align="left">
    <af:inputText value="#{bindings.AccPersonID.inputValue}"
    label="#{bindings.AccPersonID.hints.label}"
    columns="#{bindings.AccPersonID.hints.displayWidth}"
    maximumLength="#{bindings.AccPersonID.hints.precision}"
    simple="true"/>
    </td>
    </tr>
    <tr align="left">
    <td align="right">
    <af:outputLabel value="#{bindings.PersonName.hints.label}"/>
    </td>
    <td align="left" colspan="5">
    <af:inputText value="#{bindings.PersonName.inputValue}"
    label="#{bindings.PersonName.hints.label}"
    columns="#{bindings.PersonName.hints.displayWidth}"
    maximumLength="#{bindings.PersonName.hints.precision}"
    simple="true"/>
    </td>
    </tr>
    <tr align="left">
    <td align="right">
    <af:outputLabel value="#{bindings.DateFrom.hints.label}"/>
    </td>
    <td align="left">
    <af:inputDate value="#{bindings.DateFrom.inputValue}"
    label="#{bindings.DateFrom.hints.label}"
    simple="true">
    <af:convertDateTime pattern="#{bindings.DateFrom.format}"/>
    </af:inputDate>
    </td>
    <td align="right">
    <af:outputLabel value="#{bindings.DateTo.hints.label}"/>
    </td>
    <td align="left">
    <af:inputDate value="#{bindings.DateTo.inputValue}"
    label="#{bindings.DateTo.hints.label}"
    simple="true">
    <af:convertDateTime pattern="#{bindings.DateTo.format}"/>
    </af:inputDate>
    </td>
    </tr>
    <tr>
    <td align="right">
    <af:commandButton actionListener="{bindings.Execute.execute}"
    text="#{bundle.FindBtn_LABEL}"
    disabled="#{!bindings.Execute.enabled}"
    icon="/images/find.png"/>
    </td>
    <td align="left">
    <af:commandButton text="#{bundle.FindClearBtn_LABEL}"
    icon="/images/find_clear.png"
    action="#{PeopleBean.onClearVCBtn}"/>
    </td>
    </tr>
    </table>
    </af:showDetailHeader>
    </td>
    </tr>
    </table>
    Also I have a result table for the search panel, but I don't believe the problem can be there because it works fine when I search in fields different by inputDate.
    Do you have any suggestions?

  • Problem with Date-Field

    Hi,
    I have a problem with a date-field. Maybe I must describe the problem more detailled, but first I just want to ask you, if you know the following error-message: "21.10.2010 kommt nicht in der Menge der erlaubten Werte vor". I don't know the correct translation but it must be something like this: "21.10.2010 does not occur in the quantity of the permitted values". I don't find the position in the sourcecode of this message. And I know, that this message isn't thrown by a functionblock from SAP. So what is the describtion of this message?

    Yes I have a date field in my form. Ok I must describe it more detailled. I have an employee searchfield. After select an employee you see a form. After filling the form you click on "Send". It creates a ticket and sends the data to the Backend and jumps back to the employee search field. Untill this point everything works fine. There is no problem with the datefield. Now I want to create the form. I choose an employee and fill the form. But now it comes this message. But not after clicking the "send" button. The message comes after changing some data (e.g. change a radio button). So it looks like a validationproblem, but only at the second creationprocess. Maybe the first date is in some cache? I don't know...

  • Problem with date fields in where clause after changing driver

    Hi,
    We have changed the oracle driver we use to version 10
    and now we have some trouble with date-fields.
    When we run this SQL query from our Java program:
    select *
    from LA_TRANS
    where LA_TRANS.FROM_DATE>='20040101' AND LA_TRANS.FROM_DATE<='20041231'
    We get this error code:
    ORA-01861: literal does not match format string
    The query worked fine whit the previous driver.
    Is there some way I can run a SQL query with date fields
    as strings in the where clause?
    Thanks!

    Keeping the argument of standard SQL or not aside, comparing DATE columns to a constant string (which looks like a date in one of the thousands of the formats available, but not in others) is NOT one of the best programming practices and leads to heartburn and runtime errors (as you have seen yourself).
    I would rather compare a DATE to a DATE.
    Also, constants like that would be another issue to fix in your code:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:6899751034602146050::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:528893984337,

  • Problem in date field

    Hello All,
    I have a form which has several date fields.I want to autopopulate these dates to the current date unless and until the user changes it. For ex: We have a DateField 1: When the form opens it shows today's date. If the user does not change this date and if the form is again opened 2 days after,then it shows today's date instead of showing the date which is 2 days after.
    Thanks.
    Bibhu.

    Hi Bibhu,
    There are two problems trying to implement this:
    Preventing the script that calculates the current date, from firing when the form is reopened. This script is probably in the docReady event of the current date field.
    If the form is reopened and the user enters with the field that has the script to set the form data input date then this script will fire again, changing the date.
    I think your best option is to have two readOnly date fields, currentDate (visible initially) and dataInputDate (hidden). These fields would be directly aligned one on top of the other.
    Then in the field that you select as triggering the setting of the date that makes when the user input data you would hide the currentDate and show the dataInputDate. Example in the exit event
    if (this.rawValue !== null)
         currentDate.presence = "hidden";
         dataInputDate.presence = "visible";
         //... set the date for the dataInputDate
    else
         currentDate.presence = "visible";
         dataInputDate.presence = "hidden";
         dataInputDate.rawValue = null;
    Make sure the preserve script changes is ticked in the File > Form Properties > Defaults tab.
    As I say, if this field is re-entered and exited again at any stage then the script will re-fire and change the date.
    Hope that helps,
    Niall

  • JSTL sql:query date field has zero time part

    I have a little JSP where I am using JSTL to do a query against a table "ph_application" that has a date field "rundate". This field has many different dates and times in it.
    Here is the code snippet:
    <sql:setDataSource url="jdbc:oracle:thin:@oraprd02:1521:ipp4" user="site" password="pmc_site"/>
    <sql:query var="application" sql="select * from ph_application"/>
    <c:forEach items="${application.rows}" var="row">
    <tr>
    <td><c:out value="${row.name}" default=" " escapeXml="false"/></td>
    <td><fmt:formatDate value="${row.rundate}" type="both"/></td>
    </tr>
    </c:forEach>
    The resulting date/time output always has a 12:00:00 AM time regardless of what is actually in the table. I have changed the fmt:formatDate to a c:out of the row.rundate.time value and it appears that the time part of the date is actually zero at this point.
    Is there an inconsistancy between the oracle date type and what JSTL is expecting (somewhere)?
    Any help and/or verification is appreciated.
    Richard

    I'm running this from within JDeveloper 10g.

  • Problem with date field (truncation)

    Hi guys!
    I have an interface between Oracle and Oracle. My LKM is SQL to SQL and my IKM is SQL Control Append.
    In the source table i have a date with a hour but after executing the interface in the target date field I receive only date without hour...
    Do you know where it can be truncated ?
    With regards,
    PsmakR

    This an Oracle JDBC Driver error...
    Try this to fix the issue:
    Go to Topology Manager and from the Physical Architecture > Technologies > Oracle > your Data Server > Properties tab, add the oracle.jdbc.V8Compatible property and set its value to true.
    Doing that you can loose the millisecond precision for timestamps format.
    You can also have a try with the Oracle JDBC Driver version 11.1

  • Problem updating date field on user table

    Hi,
    I am having difficulty updating the value for a date field on a user defined table.  All of the other fields update fine.  Below is the code I am using.  Does anyone have any suggestions?  I have tried updating to both a date variable or a string variable.  Thanks in advance for your help
    Dim d As Date
        d = CDate("01/01/2004")
        pRecord.GetByKey (editForm.Items("Code").Specific.String)
        pRecord.UserFields("U_CardCode").Value = editForm.Items("CardCode").Specific.String
        pRecord.UserFields("U_CardNbr").Value = editForm.Items("CardNbr").Specific.String
        pRecord.UserFields("U_CardType").Value = editForm.Items("CardType").Specific.String
        pRecord.UserFields("U_ExpDate").Value = d
        pRecord.UserFields("U_Name").Value = editForm.Items("Name").Specific.String
        pRecord.UserFields("U_CVN").Value = editForm.Items("CVN").Specific.String
        pRecord.UserFields("U_Addr1").Value = editForm.Items("Addr1").Specific.String
        pRecord.UserFields("U_Addr2").Value = editForm.Items("Addr2").Specific.String
        pRecord.UserFields("U_City").Value = editForm.Items("City").Specific.String
        pRecord.UserFields("U_State").Value = editForm.Items("State").Specific.String
        pRecord.UserFields("U_Zip").Value = editForm.Items("Zip").Specific.String
        If editForm.Mode = fm_UPDATE_MODE Then
            pRecord.Update
        End If

    I think I have figured it out.  The cardtype field (which I was also updating) has a list of valid values.  If I didn't specify a value for this field none of the other fields would update either.  I'm still not sure of the reason for this behavior.

  • Having problem querying data from database

    I'm trying to setup a query form to see if the username and password entered is already in a database. If it is then a Static Text will give a positive message, if not then the user would be asked to register. My query doesn't seem to work, since every time I run it the Static Text doesn't show anything after I hit my submit button. Any help would be great.
    public String loginButton_action() {
    // TODO: Process the action. Return value is a navigation
    // case name where null will return to the same page.
    String currentuser = (String) regusernameTF.getValue();
    String currentpass = (String) regpasswordTF.getValue();
    try {
    connection = DriverManager.getConnection(Database_URL);
    statement = connection.createStatement();
    ResultSet resultset = statement.executeQuery(
    "SELECT Username ,Password FROM CustomerInfo" +
    "WHERE (Username =' " currentuser " ') ");
    connection.commit();
    statement.close();
    connection.close();
    String loggeduser = resultset.getString(1);
    String loggedpass = resultset.getString(2);
    boolean compare1 = loggeduser.equals(currentuser);
    boolean compare2 = loggedpass.equals(currentpass);
    if ((compare1==true) || (compare2==true)){
    messageST.setRendered(true);
    messageST.setText("Login Successful");
    else {
    messageST.setRendered(true);
    messageST.setText("Username & Password not Valid." +
    "Please Check Entry or Register to Login");
    catch (Exception e){
    e.printStackTrace();
    return null;
    Edited by: mavrik5150 on Feb 9, 2008 4:49 PM
    Edit: Forgot to mention the Database does have data already populated into it

    Hey Thanks guys for the tips, I was able to fix one problem, now I can get the Static Text field to display a message but I can't get the error message to appear when I purposly enter a wrong password or username. If I enter a correct username I get a successful message, even when I enter the wrong password. Here's the fixed code:
        public String loginButton_action() {
            // TODO: Process the action. Return value is a navigation
            // case name where null will return to the same page.
            Object currentuser =  regusernameTF.getValue();
            Object currentpass =  regpasswordTF.getValue();
            try {
            connection = DriverManager.getConnection(Database_URL);
            statement = connection.createStatement();       
            ResultSet resultset = statement.executeQuery(
                    "SELECT Username ,Password FROM CustomerInfo WHERE (Username ='"+currentuser+"') ");       
    //        connection.commit();
    //        statement.close();
    //        connection.close();   
            while (resultset.next()){
            String loggeduser = resultset.getString("username");
            String loggedpass = resultset.getString("password");
            boolean compare1 = loggeduser.equals(currentuser);
            boolean compare2 = loggedpass.equals(currentpass);
            if (compare1 || compare2){
                messageST.setRendered(true);
                messageST.setText("Login Successful");
            else {
                messageST.setRendered(true);
                messageST.setText("Username & Password not Valid." +
                        "Please Check Entry or Register to Login");
            catch (Exception e){
                e.printStackTrace();
            return null;
        }

  • Mapping problem for date field

    Hi XI Friends..
    In my file to idoc scenario..
    i have field date value :2006-10-10T14:10:10
    i have convert the above field into two fields idate :20061010
    itime:141010
    i used substring datetransfer functions..
    but in static test of message mapping ..i am getting value for itime as 021010
    if we give before 12:00:00 its converting properly..after 12.:00:00 its taking 12hr format only..
    please guide me..
    regards
    ram

    Hi Ram,
    Is this still a problem?
    I think the hint will also work in this case:
    sourcefield --> replaceString(sourceField/constant[T]/constant[]) --> TransformDate(yyyy-mm-ddHH:MM:SS --> HH:MM:SS) --> targetFieldTime
    sourcefield --> replaceString(sourceField/constant[T]/constant[]) --> TransformDate(yyyy-mm-ddHH:MM:SS --> YYYYMMDD) --> targetFieldDATE
    Daniel

  • Problems query data after data migration to Hana

    Hi We currently have 2 BW environments: Release: 701 SP-Level: 0014 Support Package: SAPKW70114 DB: No Hana Release: 740 SP-Level: 0005 Support Package: SAPKW74005 DB: Hana It was necessary to migrate data cubes BW 701 -> BW 740, because in ECC only history of the last 18 months is maintained. After this migration, when I make a query in Query Designer and I use between in "Filters and Restrictions" no returned values​​, but if I include the value and not use the between the values are displayed. For example: I created a query with: one key figure, Comp_Code, Material and Fiscper. On filters and restrictions I informed that should return only the materials between 0001 and 0003. When running the query does not return values​​, but if I change the filter to only return materials 0001, 0002 and 0003, the query returns data. Note .: This problem occurs only with the migrated data from the BW 701, loads of ECC deltas are functioning normally. Could you help me solve this issue? Best Regards

    Important point: I found that if you run the query in RSRT "Execute + Debug" button and do not use the option "Do not use SAP HANA / BWA Index (0)" the query runs without problems.
    Additional Information:
    - BW on Hana environment 740 is a new installation.
    - To load the historical data for the BW on Hana was created an RFC with the BW 701, classic BW as source system to new BW HANA.
    - BW 701 was generated Export Data Sources ( From cube to cube, from DSO to DSO) and we used of data sources to migrate historical data.
    - Then BW on Hana is a new installation, but only the historical data were extracted from the BW 701 (no Hana)
    - Export Data source generated on DSO data is ok, but the Data source of export from a cube, data is not ok. After data load this historical data, when I make a query in Query Designer and I use between in "Filters and Restrictions" no returned values, but if I include the value and not use the between the values are displayed, but the problem occurs only in the query on the Cube.
    - Are there any recommended when historical data is extracted on the Cube by Export Data Source?

  • Year getting reduced by 1, when querying date fields

    Hi, I am an Oracle retail support engineer. One of my clients logged an SR with the following:
    When querying application table (shown below), the date comes out as corrupted (data snippet also shown below):
    Query:
    select create_date, to_char(create_date,'DD-MON-RRRR') from shipment_table;
    Result:
    CREATE_DATE TO_CHAR(CREATE_DATE,'DD-MON-RRRR')
    08-JAN-10     08-JAN-2009
    08-JAN-10     08-JAN-2009
    08-JAN-10     08-JAN-2009
    08-JAN-10     08-JAN-2009
    08-JAN-10     08-JAN-2009
    Any idea, what can cause this? Any help is greatly appreciated.
    Thanks
    Srinivas

    Unfortunately, i'm not able to produce that error.
    scott@ORCL>
    scott@ORCL>select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Elapsed: 00:00:00.11
    scott@ORCL>
    scott@ORCL>
    scott@ORCL>with shipment
      2  as
      3    (
      4      select to_date('08-JAN-10','DD-MON-YY') create_date from dual
      5      union all
      6      select to_date('08-JAN-10','DD-MON-YY') create_date from dual
      7      union all
      8      select to_date('08-JAN-10','DD-MON-YY') create_date from dual
      9      union all
    10      select to_date('08-JAN-10','DD-MON-YY') create_date from dual
    11      union all
    12      select to_date('08-JAN-10','DD-MON-YY') create_date from dual
    13    )
    14  select create_date,
    15         to_char(create_date,'DD-MON-RRRR') char_date
    16  from shipment;
    CREATE_DA CHAR_DATE
    08-JAN-10 08-JAN-2010
    08-JAN-10 08-JAN-2010
    08-JAN-10 08-JAN-2010
    08-JAN-10 08-JAN-2010
    08-JAN-10 08-JAN-2010
    Elapsed: 00:00:00.04
    scott@ORCL>
    scott@ORCL>What is your Oracle version?
    Regards.
    Satyaki De.

  • Problems entering data fields

    wheen ever I try to enter data properties my program freezes

    I open my dashbord and for example single value box is opened, when I try to link the sigle value box to a data cell it will not allow me and the range box does not appear and the icons on my toolbar become inactive. the product is present 2008.

  • Date field performance

    hi
    The query below works well giving me a few 1000 records in 10-14 secs.
    SELECT p1.A AS "Service Number", p.1B AS "Status",
    C AS "Suspended Date",
    D AS "Reason for suspension"
    FROM inst_prod p1, reason p2
    WHERE p1.b = 'SUS'
    AND p1.reaon_id = p2.reason_cd
    But the same query takes 8-10 mins if i add another date condition to it.
    SELECT p1.A AS "Service Number", p.1B AS "Status",
    C AS "Suspended Date",
    D AS "Reason for suspension"
    FROM inst_prod p1, reason p2
    WHERE p1.b = 'SUS'
    AND p1.reaon_id = p2.reason_cd
    and trunc(p1.c) between to_date('24-Aug-2006','dd-Mon-yyyy') and
    to_date('31-Aug-2006','dd-Mon-yyyy')
    Is it because of the TRUNC function ?
    Can someone help in fine tuning this query.
    Thanks in advance
    Vamsi

    There is no such issue as "Date field performance". Reason: This implies a consistent and inevitable performance problem when using a date column as oppose to a numeric or varchar column. This is false.
    A date column is no slower or no faster than a number or varchar2 column. The speed is determined by what you, the developer or user, does with the contents of that column.
    The 1st Step in "Determining The Cause Of A Performance Problem":
    Look in the mirror.
    The vast majority of performance issues are caused by us, because we are ignorant and doing the wrong thing, misunderstand some basic concept, or worse of all, think we know better and purposefully ignore fundamentals.
    Whenever I hit a problem in software engineering, I always blame myself first, before blaming the software. Something like, "you screwed up again Verreynne!". ;-)
    It is easy to fall in the trap of "oh, it is not my code, it is because of how the software (Oracle) does this or that (cause performance problems with date fields)".
    Don't.
    > Is it because of the TRUNC function ?
    Yes, that could be a factor. Let's say you have an index on COLUMN_FOO. Data type not important.
    So, great, you can write a SQL like this and Oracle will be able to use the index for optimal perfomance:
    SELECT * FROM my_table WHERE column_foo = <some-value>
    However, what happens to that index when you write the following?:
    SELECT * FROM my_table WHERE FUNCTION(column_foo) = <some-value>
    The index on COLUMN_FOO is rendered useless. Why? Because the predicate does not compare COLUMN_FOO with some-value. The predicate states that the return value of FUNCTION() needs to be compared to some-value.
    So the index cannot be used. Every single row in MY_TABLE has to be read, every single row's COLUMN_FOO has to be run via FUNCTION() and only then can the comparison to some-value be done.
    > Can someone help in fine tuning this query.
    As others already stated, you need to look at the execution plans of the two queries and determine what the impact is when you add the TRUNC(date) predicate.

  • Universe Turns Bex Date fields to Character

    We are noticing that the universes that we creat are turning all date fields from the bex query to charachter fields. When we try to change the field back to a date in the universe it fails saying that the "driver is not capable". This is usually tied to bad data in the columns or a date format issue. Has anyone seen this and come up with a workaround?

    Hi Ingo,
    We r facing the same problem with date fields.
    The universe is built on SAP BI Query, the data model is as follows:
    DSOs> Infoset-> Multiprovider->SAP BI Query->Universe
    There are  Date variables (DATS Type) defined in the SAP BI query.which are not appearing in calander format in WEBI report at selection prompts screen, rather it is displaying as list of values.
    I checked at the universe level the date dimension for that variable is reflecting as character data type instead of date data type.
    I dont find any key detail object under date dimension whose data type is DATE.
    Edited by: Nisha Makhija on Jul 17, 2009 8:39 PM

Maybe you are looking for

  • Reports 6i and mail

    Hi all, how can i read the report that i sent it to my mail through the option that exits in report 6i. Is extension is (eps). Best Regards, Hany

  • LegendItem styling

    Hi All, For PIE chart, i need to create clickable legend items. This can be easily done by using itemClick attribute on the <mx:Legend> tag. But i am not able to do following 1. display underline for the LegendItem label 2. display hand cursor for th

  • Problems updating ipod with Microsoft Outlook

    It used to work just fine, but now says it needs a more current version of Outlook. I'm not in a position to buy the update right now. Are there special settings I can use to keep me using what I've got? Many thanks!

  • Import camera raw files from Canon 70D to PSE 10

    I downloaded the new DNG converter, and I am still unable to open the camer raw files.  Please help!

  • Statement trigger

    When do we use statement triggers? i need one practical example... like row level triggers help in audit or journalling. Plz reply asap.