Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC insert images into a Mysql database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Clark
insert images into a Mysql database
1 Answer(s)      4 years and 2 months ago
Posted in : JDBC


How can I insert images into a Mysql database?


Advertisement
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
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
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 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
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
Mysql Insert
Mysql Insert       Mysql Insert is used to insert the records or rows to the table. Understand with Example The Tutorial illustrate an example from 'Mysql Insert'.To grasp
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
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 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
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: Insert Data Delete Data Thanks
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
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;"> <
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
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 Here Thanks
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
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
MySQL PHP Insert
the database:".mysql_error()); $sql="insert into mytable (Empid,Empname... MySQL PHP Insert       Mysql PHP Insert is used to execute the Mysql function ( ) insert
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
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
how to retrieve images from database to jsp?
how to retrieve images from database to jsp?  Hi sir,i want to stores images along with the name and price with database and retrieve it on jsp.and... urgent.   1)images: <%@ page import="java.sql.*,java.io.*,java.util.
Advertisements
 

 

 

DMCA.com