• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inserting BLOB data

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Vamsi mb",
Please check your private messages.
-Ben
 
Vamsi bhujanga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved this issue.
If anybody needs assistance,send me a private message
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic