date problem...again..

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 ?
fks2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jarasaCommented:
Hi could you please post you SQL STATEMENT??
I think there is could be the problem.

Javier
0
KuldeepchaturvediCommented:
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
fks2Author Commented:
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
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

jarasaCommented:
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
KuldeepchaturvediCommented:
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
kennethxuCommented:
>>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
fks2Author Commented:
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
fks2Author Commented:
customer_0005fconfirm$jsp.java [157:1] variable eda might not have been initialized
                    System.out.println("EDA (b4 addtime) = "+ eda);
 
0
KuldeepchaturvediCommented:
do a eda=null;
that should also take care of compilation atleast...
0
fks2Author Commented:
:-)
ok.
0
fks2Author Commented:
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
KuldeepchaturvediCommented:
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
jarasaCommented:
>>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
kennethxuCommented:
>> insert into purchase values(?,?,?)
does your table has more then 3 columns? try:
insert into purchase( customer, warranty, eda ) values(?,?,?)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ajtiwariCommented:
i advice u to write stored procedure for this same purpose and call it from your java programe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.