aspose file tools*
The moose likes JDBC and the fly likes Inserting BLOB data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting BLOB data" Watch "Inserting BLOB data" New topic
Author

Inserting BLOB data

Vamsi bhujanga
Greenhorn

Joined: Jun 14, 2008
Posts: 16
Hi
I need to insert a tsv file in a table which has a BLOB column.
I have written a code in the following way and iam success in this way:
1)Create a file : File file = new File("ex.tsv");
2)Create a writer : Writer write=null;
3)Assigned the writer as the inputstream for the file.
4)Then inserted data into file
5)Create a prepare statement = pre
6)Insert statement
8)Create a fileinputstream which takes the above file : fin
7)Insert the above created file into the table using pre.setBinaryStream

But the issue is our framework doesnot allows to create file

Is there a way such that without creating file,i insert the data into the BLOB column?

Please give the sample code if you have.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31068
    
232

Vamsi,
Welcome to JavaRanch!

Where does the file come from? In other words, you are getting the TSV file from somewhere. What format is it in? byte[], pointer to a file on disk, etc. Step 4 is the one I am confused about. The answer to this will affect the answer to your question.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"Vamsi mb",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Vamsi bhujanga
Greenhorn

Joined: Jun 14, 2008
Posts: 16
Thanks for the reply.I would have kept the sample code as my questions are confusing.
Anyhow,here is the sample code.



In the above code,while creating a file itself,iam getting security issue as it is directly creating at the server.Later on i understood that iam not supposed to create a file at all (not even in local desk temporarily) but insert the data in the format which i showed above (Line numbers:6 to 10).
Is there any way of inserting the same data into BLOB column.Can you send me the sample code.(Not sure: Can we convert into bytes and insert into BLOB.)
Please suggest
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18988
    
    8

As Jeanne already said, instead of using a FileInputStream, use an InputStream that is based on the original data. You still didn't say where the original data is coming from, so it's rather difficult to suggest how you might get an InputStream from it. Would you like to explain that?
Vamsi bhujanga
Greenhorn

Joined: Jun 14, 2008
Posts: 16
The file is not coming from anywhere.The requirement is to insert the data into the BLOB column in the format i have shown.hence,i tried to create a file.But,as i told you,iam not supposed to create a file.Hence,my question is whether is there any alternate way to insert the data in the same format into BLOB column without creating a file.
Vamsi bhujanga
Greenhorn

Joined: Jun 14, 2008
Posts: 16
I solved this issue.
If anybody needs assistance,send me a private message
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Originally posted by Vamsi bhujanga:
I solved this issue.
If anybody needs assistance,send me a private message
No, don't, please. Post it here.

That sort of information should be on the forum so everybody can see it and learn from it.
Vamsi bhujanga
Greenhorn

Joined: Jun 14, 2008
Posts: 16
Thanks for the suggestion given to use 'inputstream' which struck me to use the below code.
Here is the code.

You can write the above code in try-catch block according to your requirement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting BLOB data