getting null pointer exception while entering date in sql server DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TutSav
    New Member
    • Sep 2016
    • 1

    getting null pointer exception while entering date in sql server DB

    Sqlserver table
    QualifyDate DATETIME;
    RenewalDate DATETIME
    ---
    on Bean qualifydate
    private Date QualifyDate;

    private Date RenewalDate;
    public Date getQualifiyDate () {
    return QualifyDate;
    }
    public void setQualifiyDate (Date QualifyDate)
    {
    this.RenewalDat e=RenewalDate;
    }
    ---------------------------------------------
    ON DAOImpl(java file)
    try{
    ppds.setDate(8, new Date(asb.getQua lifiyDate().get Time()));
    }
    catch(NullPoint erException nfe){
    nfe.printStackT race();
    -------------------
    try{
    ppds.setDate(10 ,new Date(asb.getRen ewalDate().getT ime()));
    }
    catch(NullPoint erException npe){
    npe.printStackT race();
    }
    -----------------
    ON servlet
    try {
    Date dob = new SimpleDateForma t("YYYY-MM-DD HH:MM:SS").pars e(request.getPa rameter("sqfdt" ));
    asb.setQualifiy Date(dob);
    } catch (ParseException e) {
    e.printStackTra ce();
    }
    --------------
    try {
    Date doba = new SimpleDateForma t("YYYY-MM-DD HH:MM:SS").pars e(request.getPa rameter("srnldt "));
    asb.setRenewalD ate(doba);
    } catch (ParseException e) {
    e.printStackTra ce();
    }
    ---------
    After submitting the Form data don't get inserted to the database
    instead says null pointer exception.
    Please helps to resolve the Problem sir,
    IDE is netbeans.
    Thankyou
    Sincerly Your.
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    The problem is that your formatter SimpleDateForma t is not recognising the input that you gave it, so it returns NULL.

    I suggest that you experiment with SimpleDateForma t in a stand-alone test program, so you can understand how it really works. If you cannot do this, then you are not going to get very far with server-side code.

    Several things to try:
    1. Verify that your calls get the correct data before inserting into the database.
    2. Verify that the parsing is correct, and returns a non-NULL value.
    3. Figure out how to handle errors - do you reject all of the transaction, or keep the completed portions?
    4. Include exception output, so that we can see what really is happening.

    Comment

    Working...