473,789 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing image in database...

10 New Member
i have some problem on ilplementing the code for the insertion of image into database that didnot get how to use the code for image storege.so can u help me in the use for the code by which i want to store the image of teacher with their respective database and i also have to retrive the same when i want to see the details of teacher..here is the code-

import java.io.*;
import java.sql.*;
import java.util.*;

public class StoreFile
{
Connection con=null;
DataBase db = null;
String filename=null;
String filedesc=null;

public StoreFile()
{

}

public StoreFile(Strin g filedesc,String filename)
{
this.filedesc = filedesc;
this.filename=f ilename;
}

public void storeFile() throws Exception
{
System.out.prin tln("Before DataBase Connection ");
PreparedStateme nt pst = null;
try
{
db = new DataBase();
con = db.getConnectio n();
pst = con.prepareStat ement("insert into files values(?,?)");
pst.setString(1 ,filedesc);
FileInputStream fis=new FileInputStream (filename);
byte[] b= new byte[fis.available() +1];
fis.read(b);
pst.setBytes(2, b);
pst.execute();
System.out.prin tln("File Stored Successfully");
}
catch(Exception e)
{
System.out.prin tln(" Problem : "+e);
}
finally
{
con.close();
pst.close();
}

}

public void getFile(String filename) throws Exception
{
System.out.prin tln("Before DataBase Connection ");
PreparedStateme nt pst = null;
ResultSet rs=null; try
{
db = new DataBase();
con = db.getConnectio n();
pst = con.prepareStat ement("select filetype from files where filename=?");
pst.setString(1 ,filename);
rs=pst.executeQ uery();
while(rs.next() )
{
byte[] b=rs.getBytes(" filetype");
FileOutputStrea m fos=new FileOutputStrea m(new File("new1.html "));
fos.write(b);
}
System.out.prin tln("File Written Successfully");
}
catch(Exception e)
{
System.out.prin tln(" Problem : "+e);
}
finally
{
con.close();
pst.close();
}

}

/*dbStatement = dbConnection.pr epareStatement( "select * from photos ");
rs=dbStatement. executeQuery();
if (rs.next()==tru e)
{
b=rs.getBytes(" photo");
FileOutputStrea m fos=new FileOutputStrea m(new File("Anil.jpg" ));
fos.write(b);
}*/


public static void main(String args[]) throws Exception
{
//System.out.prin tln("What is The File Description ");
//String filedesc = new DataInputStream (System.in).rea dLine();
System.out.prin tln("What is The File Name");
String filename = new DataInputStream (System.in).rea dLine();
//StoreFile store = new StoreFile(filed esc,filename);
//store.storeFile ();
StoreFile store = new StoreFile();
store.getFile(f ilename);
}

}

please help me as soon as posible...
Mar 31 '07 #1
0 1469

Sign in to post your reply or Sign up for a free account.

Similar topics

3
11767
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
7
3643
by: Dave | last post by:
I have a system that basically stores a database within a database (I'm sure lots have you have done this before in some form or another). At the end of the day, I'm storing the actual data generically in a column of type nvarchar(4000), but I want to add support for unlimited text. I want to do this in a smart fashion. Right now I am leaning towards putting 2 nullable Value fields: ValueLong ntext nullable ValueShort nvarchar(4000)...
5
2146
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing database since most of the sites information is all stored there. As well there would be only one place to worry about backing up. And if the file on the hard-drive was ever missing or became corrupted, I could restore it form tha database. Is...
2
1634
by: santosh_stb | last post by:
Is there any way of storing an image file into a specific Table . It would be of great help for me if i come to know something about it.
6
3048
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a folder on the server and then in the database table that I INSERT the news article, I'll store the path of the uploaded image. To me this seems a bad idea as if the image paths were changed on the
11
3252
by: bissatch | last post by:
Hi, I am trying to upload an image, create a new file based on that image and then store the base64 encoded image data in a database. I dont really know where my code is going wrong so I will just display it below: The following code contains the script to process the uploaded file, the form to upload the file and then a few links to view the file from
2
9324
by: bissatch | last post by:
Hi, I am trying to write script that is run when a form is submitted. The form contains an image input field and when submitted, the image is uploaded, resized and added as binary information to a db table. Please note, I am using a PostgreSQL database I have written all the code out below that deals with the submission processing:
4
3928
by: lorirobn | last post by:
Hi, I need to add photos to my database. Back End is on MS SQL Server (I believe 2000), and Front End is on MS Access. I have read about storing the photos as BLOBS, but I am not sure how to do this with SQL Server. Does this mean store the photo as OLE image, but do something else to it to make it a "Blob"? I have also read about linking to the photo rather than storing it on
0
1393
by: RussCRM | last post by:
I want to use a command button, say "cmdDisplayImage" to display/ transfer a captured image from the ezVidCap1 control to an image or OLE box on the same form such as "PhotoPreview" (not sure which one is possible/best...perhaps someone can help me...I'm new at this.) I really don't want to "save" it first. Then, I want another command button such as "cmdSaveImage" to save the file to a folder (such as \\Server\Database\Images when...
1
1705
by: Jonathan Wood | last post by:
My site includes a feature that allows users to upload an image. (Never more than one image per user.) I've been considering storing these uploaded images as a file on the server with a filename based on the user's ID key (a Guide). But I'm wondering what some of the advantages and disadvantages are of this approach over storing the images in the database. If it makes any difference, the image will be shown on virtually every page.
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.