?
Solved

date problem...again..

Posted on 2003-12-12
15
Medium Priority
?
1,593 Views
Last Modified: 2012-05-04
i am still confused. Hope my code and situation can be sovled.

****

//it's a string consist of dd/MM/yyyy date format
String ida= request.getParameter("InsDateA");

//Declare and initiate a date
java.util.Date eda = new java.util.Date();
..
..
Calendar f_a  = Calendar.getInstance();
..
..
..
    if (rs.next()) {
        a_term=rs.getString("FilterA");
..
..

if (ida!=null || ida!="") {
    System.out.println("Inside the null");
    f_a.setTime(df.parse(ida));
    f_a.add(Calendar.MONTH, Integer.parseInt(a_term));
    eda=f_a.getTime();
}

...
....
    if ((eda == null) || (eda.equals(""))){
            pstmt.setNull( 7, java.sql.Types.DATE );
        } else {
              pstmt.setDate(7, new java.sql.Date(eda));
        }

********
basically i accept user enter date (ida), from there i retrieve a terms (in month) from db. Then i add the ida with this terms, and get a date. Then with this date, i pump it into a Date field in my db.

the question is,
1. based on the above code, anything wrong with the ttype and the declaration?
2. I keep on getting this error;
javax.servlet.ServletException: Unparseable date: " "
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)

when i did enter the ida date. But i thought i have already check the date before i do anything.

  if (ida!=null || ida!="") {

  }

have can i sovle this error?? unparseable date ?
0
Comment
Question by:fks2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 9927406
Hi could you please post you SQL STATEMENT??
I think there is could be the problem.

Javier
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9927509
try this
String ida= request.getParameter("InsDateA");
if ((eda == null) || (eda.equals(""))){
            pstmt.setNull( 7, java.sql.Types.DATE );
        } else {
              SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy" ) ;
              pstmt.setDate(7, sdf.parse( ida ).getTime());
        }

let me know if it works
0
 

Author Comment

by:fks2
ID: 9927790
no no no...

kuldeep, nice to see you again. Hope you are not late this time for helping me. :-)

I have this senario. User enter a date, called it as ida, and i need to calculate the ExpiredDate based on the terms i retrieve from the db. I manage to print out this term and proved that can retrieve data.

**key word**: I have execute the sql statement YET!! I remark these code,

 if ((eda == null) || (eda.equals(""))){
           pstmt.setNull( 7, java.sql.Types.DATE );
       } else {
             pstmt.setDate(7, new java.sql.Date(eda));
       }

and run the same problem and have the javax.servlet.ServletException: Unparseable date: " "
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
error....

meaning to say it's before the code, and i suspect (since it's the only code) is this part

if (ida!=null || ida!="") {
    System.out.println("Inside the null");
   f_a.setTime(df.parse(ida));
    f_a.add(Calendar.MONTH, Integer.parseInt(a_term));
   eda=f_a.getTime();
}

any problem? from the code? the ida is a String, i need to set the ida into f_a as a Calendar. then i add the months into f_a. Then i retrieve the eda date after added the terms.

But when i test it, with a blank ida, it'll prompt me the error... VERY sure that i remark off the SQL part of code.

TQ.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:jarasa
ID: 9927833
Well anyway you can always parse the data as String and make the transformation on the SQL Statement that's why I asked:
pstmt.setString(7, "12/12/2003");
slq= "....... TO_DATE(?,"MM/DD/YYYY") ......"

That's what I mean. most of the time is better becose depending on the database you use Date formats are totally unuseful

Javier
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9927858
Hmm.......
just one question before we proceed.... have you tried printing the ida or eda at the console??
Imean just do a

 (ida!=null || ida!="") {
    System.out.println("Inside the null");
    System.out.println(ida);
 f_a.setTime(df.parse(ida));
    f_a.add(Calendar.MONTH, Integer.parseInt(a_term));
   eda=f_a.getTime();
System.out.println(eda);
}
 and let us see what we get..... I guess your calculation and juggeling around the date is getting u in trouble.....
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9932806
>>Well anyway you can always parse the data as String and make the transformation on the SQL Statement.
That might work, but use prepare statement with sql.Date object is better approach then this.
>>  slq= "....... TO_DATE(?,"MM/DD/YYYY") ......"
a lot of database doens't support to_date function.

>>  Unparseable date: " "
notice that there is a space between the quote, and it also should be AND, not OR try:
(ida!=null && ida.trim().length() > 0) {
  ...
0
 

Author Comment

by:fks2
ID: 9939400
yeah, you are right ken,
the space it between.
:-)


if (ida!=null && ida.trim().length() > 0) {
    System.out.println("Inside the null");
    System.out.println("IDA = "+ ida);
    System.out.println("EDA (b4 addtime) = "+ eda);
    f_a.setTime(df.parse(ida));
    f_a.add(Calendar.MONTH, Integer.parseInt(a_term));
    eda=f_a.getTime();
    System.out.println("EDA (after addtime) = "+ eda);
}

I wouldl ike to ask how can initialise a eda ?
if i declare like this,
java.util.Date eda = new java.util.Date();
it'll declare the eda as today date.

if i declare like

java.util.Date eda;

it's prompt me error saying i didn't initialise...

0
 

Author Comment

by:fks2
ID: 9939417
customer_0005fconfirm$jsp.java [157:1] variable eda might not have been initialized
                    System.out.println("EDA (b4 addtime) = "+ eda);
 
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9939842
do a eda=null;
that should also take care of compilation atleast...
0
 

Author Comment

by:fks2
ID: 9939866
:-)
ok.
0
 

Author Comment

by:fks2
ID: 9940231
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)

.
.
.
        PreparedStatement pstmt=null;
        pstmt=conn1.prepareStatement("insert into purchase values(?,?,?)");
        pstmt.setString(1, customer );
        pstmt.setString(2, warranty );

        if ((eda == null) || (eda.equals(""))){
            pstmt.setNull( 3, java.sql.Types.DATE );
        } else {
              pstmt.setDate(3, new java.sql.Date(eda.getTime()) );
        }
.
.
  purchase_number = pstmt.executeUpdate();

CONFIRMED it's the same value.. but how come it's say doesn't same?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9940280
thats a strange msg you are getting! the code above will set three parameters one way or the another..!! you sure that your table has got three columns only??
Also ( this is without a reason.... but try putting a semicolon in your query statement)....



0
 
LVL 6

Expert Comment

by:jarasa
ID: 9940654
>>a lot of database doens't support to_date function.

As far as I know MS Access does support it, anyway if they dunnot should have an equivalent, I should give it a try.

Javier
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 500 total points
ID: 9946885
>> insert into purchase values(?,?,?)
does your table has more then 3 columns? try:
insert into purchase( customer, warranty, eda ) values(?,?,?)
0
 

Expert Comment

by:ajtiwari
ID: 10127014
i advice u to write stored procedure for this same purpose and call it from your java programe
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question