Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error while doing file upload

Status
Not open for further replies.

maas

Programmer
Sep 3, 2009
148
BH
Hello All,


I am having a problem while using the file upload in the jsp.

It throws an error which is java.lang.NullPointerException jspservice (_contract((File name)).java:211) .

My code is shown below:

Code:
String cname = request.getParameter("cname"); 
  String description = request.getParameter("description"); 
  String support = request.getParameter("support"); 
  String attachment=request.getParameter("attachment"); 
  String[] userlist =request.getParameterValues("userlist"); 
  String notify = request.getParameter("notify"); 
  String vendorname = request.getParameter("vendorname"); 
  String from_dt = request.getParameter("from_dt"); 
  String to_dt = request.getParameter("to_dt"); 
  File fileNm=null; 
   
  if(attachment!=null) 
                { 
                fileNm = new File(attachment); 
                } 
   
  String connectionURL = "jdbc:oracle:thin:@X.X.X.XX:XXX:test"; 
   
  Connection conn=null; 
   
  PreparedStatement ps=null; 
         
  Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
   
   
  if (cname != null ){ 
  try 
  { 
        conn = DriverManager.getConnection(connectionURL, "test", "test"); 
         
        for (int i=0; i<userlist.length; i++){  
         
        FileInputStream fis = new FileInputStream(fileNm); 
         
        String queryString = "INSERT INTO contract_detail(contract_name,description,support,c_from,c_to,userlist,notify,vendorname,attachment) VALUES (?,?,?,TO_DATE(?,'YYYY/MM/DD'),TO_DATE(?,'YYYY/MM/DD'),?,?,?,?)"; 
 
     ps = conn.prepareStatement(queryString);   
                 
         ps.setString(1, cname); 
         ps.setString(2, description); 
         ps.setString(3, support); 
         ps.setString(4, from_dt); 
         ps.setString(5, to_dt); 
         ps.setString(6, userlist[i]); 
         ps.setString(7, notify); 
         ps.setString(8, vendorname); 
         ps.setBinaryStream(9,fis,(int)fileNm.length()); 
 
 
         ps.executeUpdate();       
         fis.close(); 
     }        
         out.println(" The Contract is updated successfully"); 
          
  }

Please advice regarding that code if it is correct or not
 
Looks ok to me as long as the attachment parameter is not null. Can you post the whole stack trace?

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top