Bookmark Topic Watch Topic
  • New Topic

Java Upload file into database field

 
Rick Banster
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a Java/JSP web site based on an Oracle 9i database. I'm trying to upload files and insert them directly into a table in my database. I'm currently using the follow code:

fs = new FileInputStream(file);

Class.forName("oracle.jdbc.driver.OracleDriver");
connection=DriverManager.getConnection("jdbcracle:thin:@---","xxx","xxx")�;
connection.setAutoCommit(false);
pstmt = connection.prepareStatement("INSERT INTO UploadsTable (ID,Uploadfile)
VALUES (1,file)" );

pstmt.setInt(1,123);
pstmt.setBinaryStream(2,fs,(int)file.length());
pstmt.executeUpdate();

pstmt.close();
fs.close();

The code uploads; however, saves the file to my server. I do not want the file saved to my server, just inserted into my database. I would like to store the WHOLE file in a field not just the contents. Files I would like to save are .txt, .sgn, html, etc...

Please help! I would really appreciate it.

Thanks
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36007
422
Eclipse IDE Java VI Editor
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!