Click here to Skip to main content
15,846,571 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am having the following code & i'm calling it through the jsp page but it giving me the
NullPointerException at this line
Java
cs.setDate(6,(Date)df.parse(ptechdatabean.getFrom_Date()));

as i m using java, jsp, jdbc, oracle 10g can someone tell me why this is so....

Java
package Ptech;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.sql.Date;

public class User_Master_procedure {

    public ArrayList Call_User_Master_procedure(PtechDataBean ptechdatabean) throws ClassNotFoundException, SQLException, ParseException {

        DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); 
        DatabaseConnection db = new DatabaseConnection();
        Connection Connect = db.Oracle_Connect();
        CallableStatement cs = Connect.prepareCall("{call Pr_User_Master_Insert(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
        cs.setString(1, ptechdatabean.getCompany_id());
        cs.setString(2, ptechdatabean.getBranch_id());
        cs.setString(3, ptechdatabean.getUser_id());
        cs.setString(4, ptechdatabean.getName());
        cs.setString(5, ptechdatabean.getPassword());
        cs.setDate(6,(Date)df.parse(ptechdatabean.getFrom_Date()));
        cs.setDate(7,(Date)df.parse(ptechdatabean.getTo_Date()));
        cs.setString(8,ptechdatabean.getStatus());
        cs.setInt(9, ptechdatabean.getEntered_By());
        cs.setDate(10,(Date)df.parse(ptechdatabean.getEntered_Date()));
        cs.setInt(11, ptechdatabean.getUpdated_By());
        cs.setDate(12, (Date)df.parse(ptechdatabean.getUpdate_Date()));
        cs.setString(13, ptechdatabean.getIp_Address());
        cs.setString(14, ptechdatabean.getMac_Address());
        cs.setString(15, ptechdatabean.getCard_Id());
        cs.setString(16, ptechdatabean.getUser_Name());
        cs.setString(17, ptechdatabean.getFlag());
        cs.registerOutParameter(18, Types.VARCHAR);
        cs.registerOutParameter(19, Types.VARCHAR);
        cs.executeUpdate();
        Connect.commit();
        ArrayList al = new ArrayList();
        {
            al.add(cs.getString(18));
            al.add(cs.getString(19));
        }

        return al;
    }
}
Posted
Updated 12-Aug-13 22:10pm
v3
Comments
Sergey Alexandrovich Kryukov 13-Aug-13 2:58am    
In what line? In all cases, use the debugger and find out. This is one of the simplest exceptions to locate and fix.
—SA

You are probably failing at parsing the date.

Please make that an extra line and check the format.
It's probably best to keep it to the default format:

Java
DateFormat df = new SimpleDateFormat();//"MM/dd/yyyy"); 

// otherCode();

String dateValue = ptechdatabean.getFrom_Date();
Date date = df.parse(dateValue);
cs.setDate(6, date);
 
Share this answer
 
Ensure that the field you're trying to get from contains a date in the format you are formatting. If the date field is null, the NullPointerException is thrown, otherwise it throws the ParseException. In your case, I think your bean is not passing the date, check your code abstraction to see where the problem really is and then try the following.
Java
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
// You don't have to cast to Date as the returned value is already formatted as a date.
cs.setDate(6, df.parse(ptechdatabean.getFrom_Date());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900