java - How to stop updating the database if the input file not selected? -


my setup this,

  1. users enters values in jsp page. in same page i've given option upload file.

  2. 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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -