java - How to stop updating the database if the input file not selected? -
my setup this,
users enters values in jsp page. in same page i've given option upload file.
when users click on save button @ end, redirects servlet , values including file gets uploaded db (i'm using sql server)
if users not upload file , click on save, query update in servlet updating '0x' file(progressfile in db) column. don't want update db when there's no file selected upload.
in jsp, <input name="file" type="file">
in servlet,
inputstream inputstream = null; part filepart = request.getpart("file"); string file = filepart.getsubmittedfilename(); if (filepart != null) { // obtains input stream of upload file inputstream = filepart.getinputstream(); } string query = "update helpdata set progressfile = ?, progressfilename = ? id='"+id+"'"; pstmt = conn.preparestatement(query); pstmt.setstring(2, file); //method insert stream of bytes pstmt.setblob(1, inputstream ); int row = pstmt.executeupdate(); if (row > 0) { system.out.println( "file uploaded , saved database"); }
how not update db when there no file selected upload?
thanks in advance..
Comments
Post a Comment