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:
Please advice regarding that code if it is correct or not
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