Uploading an image into the table

Uploading an image into the table

View Answers

March 20, 2009 at 4:36 AM

Hi friend,

Code to help in solving the problem :


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

class SaveImageToDatabase {
public static void main(String[] args) throws SQLException {
// declare a connection by using Connection interface
Connection connection = null;
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost
and database name is mahendra. */
String connectionURL = "jdbc:mysql://localhost:3306/mahendra";;
/*declare a resultSet that works as a table resulted by execute a specified
sql query. */
ResultSet rs = null;
// Declare prepare statement.
PreparedStatement psmnt = null;
// declare FileInputStream object to store binary stream of given image.
FileInputStream fis;
try {
// Load JDBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();

/* Create a connection by using getConnection() method that takes
parameters of string type connection url, user name and password to
connect to database. */
connection = DriverManager.getConnection(connectionURL, "root", "root");
// create a file object for image by specifying full path of image as parameter.
File image = new File("C:/image.jpg");
/* prepareStatement() is used for create statement object that is
used for sending sql statements to the specified database. */
psmnt = connection.prepareStatement
("insert into save_image(name, city, image, Phone) "+ "values(?,?,?,?)");
psmnt.setString(1,"mahendra");
psmnt.setString(2,"Delhi");
psmnt.setString(4,"123456");
fis = new FileInputStream(image);
psmnt.setBinaryStream(3, (InputStream)fis, (int)(image.length()));
/* executeUpdate() method execute specified sql query. Here this query
insert data and image from specified address. */
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else {
System.out.println("unsucessfull to upload image.");
}
}

// catch if found any exception during rum time.
catch (Exception ex) {
System.out.println("Found some error : "+ex);
}
finally {
// close all the connections.
connection.close();
psmnt.close();
}
}
}

Thanks









Related Tutorials/Questions & Answers:
Uploading an image into the table - JSP-Servlet
Uploading an image into the table  how to upload an image into the table in java  Hi friend, Code to help in solving the problem..."; /*declare a resultSet that works as a table resulted by execute a specified
Image uploading
Image uploading  Hi,can anyone explain the following code. The code related to uploading an image file to oracle database using java servlet. CODE import java.io.*; import java.io.IOException; import
Advertisements
uploading image in php - PHP
uploading image in php  I am looking for a PHP script to upload image into mysql database
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
change the name of the image after uploading the image
change the name of the image after uploading the image   my form consists of a textbox and uploading the image.after uploading the image i want to change the name of the image with the content of the textbox before saving
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i tried, But that image file does not read. It returns only -1 without reading that image file ... I want know that solution using by u... Thanks, P.S.N.  
uploading image in the form
uploading image in the form  Hi All, I am working to build a form like railway registration form which accepts user id and password and image for authentication. And i want all users should be able to see the image once
Uploading an image - JSP-Servlet
Uploading an image  I am doing a jsp project. In this uploading an image is a part. For that i had done a coding for uploading... and uploading is done by different jsp coding. I don't know how to code for file size
Uploading Multiple Image On Server?
Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works fine for uploading single image,but it doesn't work with uploading multiple
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
struts image uploading
struts image uploading  please let me know how to upload image in database using struts ..i have written form class and 'm hanging out in action class .... form FileUploadForm: package com.action.form; import
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
Uploading a Profile with image[file] into a sql database
Uploading a Profile with image[file] into a sql database  I need to upload a file along with the some text into a database ......[ Similar to http://www.roseindia.net/jsp/jspfileupload/employeeuploadprofile_image.shtml
uploading of image showing exception when size increases.
uploading of image showing exception when size increases.  Hi . I have a project in which the user can upload images. it works properly, but when the image size increases to arnd 1 MB or more it shows exception. I am using tomcat
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  thanks dear, but i am working in Linux Ubuntu, how can i set the path in server. my problem is i am not able to access the folders wherever we are uploading the files, we are not able
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Thanks deepak following my... to writing image file in this path.. in multipartRequest. if u have any other uploading script please help me.. thanks   Hi, Plz give
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Dear All, I am facing some problem image uploading in server that i working fine in my system, OS Ubuntu. but in server it is showing following error
add image in a row of table
add image in a row of table  i have a table in which i have to add image in its row.i am trying to add the image with the help of label i.e i have a label in which instead of passing text i have inserted image using
add image in a row of table
add image in a row of table  i have a table in which i have to add image in its row.i am trying to add the image with the help of label i.e i have a label in which instead of passing text i have inserted image using
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image on div or cell of table
image on div or cell of table  I am using ms access database and I have stored the image in access database and I have a code to display image but it display on browser but I want to display on inside the div tag or table tag pls
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  dear friend... following is my uploading code and i want to save some records....... while submitting time i am getting following error.................. HTTP
Need help in image uploading - JSP-Servlet
Need help in image uploading  hii, i have one doubt in uploading an image in jsp. I want to display image from DB to my jsp page. For that i... to remote server..??? regards Sreejith Here is my code for image uploading
Inserting Image into table
Inserting Image into table  In this section , we will insert a image into a table. For inserting image, table's field (in which image will be stored) must be define as "blob". First, Create table'inImage'
error in uploading image from jsp to oracle 10g database
error in uploading image from jsp to oracle 10g database  ... try to insert into the image into the database i got the above error please advice how to get rid of error   JSP upload image in Mysql database
Inserting Image in Database Table
Inserting Image in Database Table   ... This program helps the user to insert an image in the MySQL database table... (Image table). For inserting an image in table, we have used the SQL statement
Retrieving the Image from a database Table
Retrieving the Image from a database Table Consider a case where we want... to retrieve the image from the database table. You can do it very easily after... the image from the database table in prepareStatement() method of the Connection
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
. Is it not possible to use a image instead of normal html Browse button for uploading files...Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP  I am using the following code snippet
Insert Blob(Image) in Mysql table using JSP
Insert Blob(Image) in Mysql table using JSP In this Section, we will insert blob data(image) in Mysql database table using JSP code. A Blob stores a binary..._TO_REPLACE_8 See also :   Display Blob(Image) in Mysql table using
Inserting Image in a database Table
Inserting Image in MySql Database Table... understand the concept of inserting a image in the database table, so go through... that along with the name of the person and its information, his image should also
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
rename before uploading
rename before uploading  I need to change (rename)the file name/image name before uploading it so that the file gets uploaded on server with this new name
uploading problem
uploading problem  i use glassfish server.. using netbeans for jsp... curresponding image files start new upload"); %><...;br> <center><table border="2" > <tr><center><td
Display Blob(Image) from Mysql table using JSP
Display Blob(Image) from Mysql table using JSP In this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores... Also : Insert Blob(Image) in Mysql table using JSP Download Source CodeADS
Uploading files
Uploading files  Hi, Please provide html code for my question. I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
photo uploading
photo uploading  i want the code upload the image in oracle database
uploading a file
uploading a file  When I am trying to upload a file to another system in lan at a location "http://192.168.12.5:8080/tomcat-docs/myapps",then it is giving the following error message "http://192.168.12.5:8080/tomcat-docs/myapps
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
table
table  multiplicatyion table
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me

Ads