Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><em>i need full path to upload a file in mysql db.</em></p> </blockquote> <p>There's a major thinking mistake here.</p> <p>Imagine that <em>I</em> am the client who want to upload the file and that <em>you</em> are the server who need to get the file's contents. I give you my full local disk file system path <code>c:\path\to\sample.docx</code> as the sole information, exactly as you requested. How would you as being the server ever get its <em>contents</em>? Do you have an open TCP/IP connection to my local hard disk file system? Really?</p> <p>This isn't how uploading files works. This would only ever work if the server runs at <em>physically the same</em> machine as the client, so that you can just use <code>FileInputStream</code> with that path. This would thus only ever work in the local development environment, but definitely not in real world production where the server runs at a physically different machine than the client, separated by a HTTP connection.</p> <p>You should instead be interested in the sole file <em>contents</em> which the client has sent to you along with the HTTP request body. In HTML terms, you can use <code>&lt;input type="file"&gt;</code> for this in a <code>&lt;form enctype="multipart/form-data"&gt;</code>. A more detailed answer with full code examples can be found here: <a href="https://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet/2424824#2424824">How to upload files to server using JSP/Servlet?</a> It describes the modern Servlet 3.0 way using <code>request.getPart()</code> and the previously defacto standard Apache Commons FileUpload API.</p> <p>Once you've implemented it the right way, you should ultimately end up with an <code>InputStream</code> representing the file contents which you obtained from the Servlet 3.0 <code>part.getInputStream()</code> or the Apache Commons FileUpload <code>item.getInputStream()</code>. You can then just use <a href="http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#setBinaryStream%28int,%20java.io.InputStream%29" rel="nofollow noreferrer"><code>PreparedStatement#setBinaryStream()</code></a> the usual way to store it in the DB and <a href="http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getBinaryStream%28java.lang.String%29" rel="nofollow noreferrer"><code>ResultSet#getBinaryStream()</code></a> to retrieve it from the DB.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload