wood burning stoves 2.0*
The moose likes JDBC and the fly likes how to store image in MS SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to store image in MS SQL Server" Watch "how to store image in MS SQL Server" New topic
Author

how to store image in MS SQL Server

Lokendra Shekhawat
Ranch Hand

Joined: Jun 08, 2009
Posts: 40
hi friends,
I want to store images (.jpg or .png or .gif) in MS SQL Server 2005 database using JDBC-ODBC connectivity in servlet. can anybody give me step by step procedure to do it.
I don't wan't to store the reference to images, instead i want to store actual image file in a database.

Please give me step by step procedure to do it.

Thank You


SCJP5 93%. SCWCD 98%.

Visit my website http://www.rajasthan4tourism.com for information about rajasthan tourist places and much more.....!!!
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Have you tried anything yourself? What do you think the step-by-step procedures should be?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets, not JDBC. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

Lokendra Shekhawat wrote:Please give me step by step procedure to do it.

You'll want to read up on BLOBs in the JDBC tutorial.


[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
amrish sharma
Greenhorn

Joined: Sep 24, 2009
Posts: 20
i am using the following code for storing image in ms sql server 05

i have wriiteen the following sql script





but when executed it shows this exception

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '�'.
please help !
Lokendra Shekhawat
Ranch Hand

Joined: Jun 08, 2009
Posts: 40
I am also getting the same error. aren't there any way around it. can't we store image on the database at all???
amrish sharma
Greenhorn

Joined: Sep 24, 2009
Posts: 20
ya i think the same there is no way to store images in sql server using servlet
so i gonna change the idea now i am going to give the clients selective images only already uploaded on server..

bye with some (cry and pain)
wait wait
i also downloaded "jtds-1.2.3-dist" driver for sql server but the same problem occured now i think its a problem of ODBC or the ms sql server

loks checkout here : http://www.java.happycodings.com/JDBC/code3.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41603
    
  55
It's probably not the source of the problem, but one thing you need to fix is the following code: ReadDoesntDoWhatYouThinkItDoes

File f=new File("D://124744.jpg");
FileInputStream in=new FileInputStream(f);
byte [] b=new byte[(int)f.length()];
in.read(b);


Ping & DNS - my free Android networking tools app
malik saad
Greenhorn

Joined: Dec 15, 2011
Posts: 1

String pic="INSERT INTO Images VALUES(?)";

The above live Image as Table name ,but its entity or column is not mentioned like "INSERT INTO Images(ColumnName) VALUES(?)"; which is main requirement so makes exception ..

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

Welcome to the Ranch!

It's not required to add the column names; if you omit them it's equivalent to adding all column names. In this case there is only one column so there is no need to specify the column name.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to store image in MS SQL Server