Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting BLOB data

 
Vamsi bhujanga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34408
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Vamsi bhujanga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved this issue.
If anybody needs assistance,send me a private message
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic