insert images into a Mysql database

insert images into a Mysql database

How can I insert images into a Mysql database?

View Answers

November 15, 2010 at 1:20 PM

Hi friends

With the help of this example, you can insert image in data base...

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class InsertImageInMySql {

public static void main(String[] args) {
    try {
        int result = 0;
        String mysqlDriver = "com.mysql.jdbc.Driver";
        Class.forName(mysqlDriver).newInstance();
        String connectionString = "jdbc:mysql://192.168.10.13:3306/studentinformation";
        String username = "root";
        String password = "root";
        Connection con = DriverManager.getConnection(connectionString,
                username, password);
        PreparedStatement prestmt = null;
        // Create a binary stream
        File imageFile = new File("lotus_temple.jpg");
        FileInputStream fis = new FileInputStream(imageFile);
        String insertImage = "insert into picture values(?,?)";
        prestmt = con.prepareStatement(insertImage);
        prestmt.setInt(1, 7);
        prestmt.setBinaryStream(2, fis, fis.available());
        result = prestmt.executeUpdate();
        if (result == 1) {
            System.out.println("Image Successfully Inserted in database!");
        } else {
            System.out.println("Image not Inserted in database!");
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

}

Thanks.









Related Tutorials/Questions & Answers:
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
Advertisements
How to insert and retrieve Questions with special symbols and images into database in an ONLINE EXAMINATION project?
is " how can I insert the questions with some symbols and images into database...How to insert and retrieve Questions with special symbols and images into database in an ONLINE EXAMINATION project?  Hi guys. I am developing
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
Query to insert values in the empty fields in the last row of a table in Mysql database?
Query to insert values in the empty fields in the last row of a table in Mysql database?  I have some fields filled and some fields empty in the last row of my MYSQL database. Now I want to fill up those empty fields in the last
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert name ,city and image in database in mysql and jsp   Here is an example in jsp that insert name, city and image to database. <%@ page import
Insert current date into MYSQL database
Insert current date into MYSQL database In this tutorial, you will learn how to insert current date into database. In most of the applications, there is a need to insert date or time to database. Mysql provides several datatypes
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java  How To Store Multilple Images In MySQL database dynamically with image uploader
How to insert and retreive an image in mysql database using spring mvc framework???
How to insert and retreive an image in mysql database using spring mvc framework???  I ve solved this problem based on the Product Search Application. Those who need this concept and code segment kindly copy it. Thanks and All
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... jsp form and want inserting it into my mysql database table. but i am having a problem to insert multiple rows into database using a single insert query
how to retrieve text and images from mysql database and show on html page using jsp servlet
how to retrieve text and images from mysql database and show on html page using...; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Insert title here h3... Complaints: Complaint Timing User Name Complaint Details Complaint Images
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from 'Mysql Insert
insert Images using if condition on a button in NetBeans
insert Images using if condition on a button in NetBeans  I wantted to insert Images using if condition on a button that is performed to change the picture on one single label. how shuold i do this ? and also give me an example
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
insert query in mysql
insert query in mysql  insert query in mysql not working   [INSERT INTO Birthdays(firstname, lastname, birthday, group) VALUES('Sam','Smith','June','Junior
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some solution. Your inputs is valuable to me.   Hi Friend, Visit HereADS
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
How to insert image in MySQL database using sql query?
Insert image in MySQL database using sql query  ... in MySQL database and then used the query to insert the data... tutorial of "How to insert image in MySQL database using sql query?": So
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation: create database studentdb; create table stu_info ( ID int not null auto
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it
Insert data in mysql database through jsp using Prepared Statement ---- Please Resolve it   I have tried the following code Database creation: create database studentdb; create table stu_info ( ID int not null auto
JDBC Video Tutorial- How to insert data into MySQL database table?
to insert into database: Connect to MySQL Database using JDBC Create...JDBC Video tutorial example for inserting data into MySQL database JDBC... into MySQL database. We have used the MySQL database as it is easy to download
Insert image in database
Insert image in database  Want a jsp-struts program in which the imageFile is in the form of getter and setter and inserted in the database as a Blob using . and then download the image and show on next jsp pg. No use
insert data into database
insert data into database  hi,thanks for reply just i am doing student information project,frontend is jsp-servlet and backend is msaccess2007. i... and studentmaster is the database table name. i am using same details. Now give
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database...=con.prepareStatement("insert into studentmaster(slno) values('"+batch+"')"); i
unable to insert data into database
unable to insert data into database    hello.i have a problem... the eid based on ename and the other is inserting data into database based...=ps1.executeQuery(); ps2 = con.prepareStatement( "insert
unable to insert data into database
unable to insert data into database    hello.i have a problem... the eid based on ename and the other is inserting data into database based...=ps1.executeQuery(); ps2 = con.prepareStatement( "insert
unable to insert data into database
unable to insert data into database    hello.i have a problem... the eid based on ename and the other is inserting data into database based...=ps1.executeQuery(); ps2 = con.prepareStatement( "insert
unable to insert data into database
unable to insert data into database    hello.i have a problem... the eid based on ename and the other is inserting data into database based...=ps1.executeQuery(); ps2 = con.prepareStatement( "insert
example of before insert trigger in mysql
a simple before insert trigger in MySQL? Thanks   Hi, The before insert... in MySQL database server and executed on the server itself. So, its very fast. First... and check the data inserted into database. Here is the sql to insert sample
Inserting values in MySQL database table
to insert the values in the database. Here we are going to see, how we can insert values in the MySQL database table. We know that tables store data in rows... Inserting values in MySQL database table   
MySQL PHP Insert
MySQL PHP Insert       Mysql PHP Insert is used to execute the Mysql function ( ) insert...,'Q','26000'); Query OK, 1 row affected (0.01 sec) mysql> insert
Oracle Database - Insert System Time
Oracle Database - Insert System Time  Hi I want to insert only system time dynamically using a statement but not a prepared statement into Oracle Database please suggest me any code
How to insert data into MySQL Table?
How to insert data into MySQL Table?  Hi, How to insert the data into MySQL Database? Please explain me with the examples and videos thanks. Thanks   Hi, The insert into query is used to insert the data into MySQL
how to store and retrieve images int and from the database using php
how to store and retrieve images int and from the database using php  please anyone can help me in storing the images and retrieve it back from the Mysql database using php
display multiple images from postgres database in jframe
display multiple images from postgres database in jframe  i just want to display multiple images on jframe by firing a query on postgres database
Insert data in mysql database through jsp using prepared statement
Insert data in mysql database through jsp using prepared statement...; This is detailed jsp code that how to insert data into database by using prepared statement... 'student' in mysql and table named "stu_info" in same database by sql
insert data into database
insert data into database  type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: General error
insert date into database using jsf
insert date into database using jsf  Hello I need a simple example of source code to insert a date into a database using jsf what do I have to put in backing bean and page jsf ( i need juste a date ) thanks
pint multiple images from blob database
pint multiple images from blob database  How to display multiple images using blob from mysql database. The program code is as below: <TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"> <
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query... between your Tomcat server & Mysql database Table. Code to insert row in Mysql
To insert maximum number of data in database.
To insert maximum number of data in database.  how to change string data type into clob data type in jsp   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jdbc/insert-clob
update mysql database
update mysql database  update mysql database
MySql database - SQL
MySql database  hello sir, i am trying to write a code which should take images from a particular folder and data from MSAccess..please help me..thank you....   Images If you want
To insert attachment file in database in JSP.
To insert attachment file in database in JSP.  I am doing project in JSP. How to insert attachment file in mysql database? Please suggest some... = null; String connectionURL = "jdbc:mysql://localhost:3306/test"; ResultSet rs
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from the database using servlet on the jsp page and there is checkbox corresponding... should i insert only checked data into database on submission.   We
Mysql Multiple Date Insert
Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert... The Section of Tutorial illustrate an example from 'Mysql Multiple Column Insert
Insert file data into database
Insert file data into database In this section, you will learn how to insert the file data into database. Description of code: Here we have used FileReader.... Now to insert this data into the database, we have established a database
Mysql Multiple Date Insert
Mysql Multiple Date Insert       Mysql Multiple Column Insert is used to add or insert... of Tutorial illustrate an example from 'Mysql Multiple Column Insert
how to insert excel file into mysql datbase in servlet
how to insert excel file into mysql datbase in servlet  emphashow to insert excel file into mysql datbase inservletized text

Ads