Insert an Image in JDBC

Insert an Image in JDBC

am trying to insert an image in jdbc but img not inserted error came what can i do.. The Code IS

package com.jdbc.concepts;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.io.*;
public class ImageInsert {

    /**
     * @param args
     */
    public static void main(String[] args)throws Exception
    {
        // TODO Auto-generated method stub
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:a2","scott","tiger");
        java.sql.PreparedStatement pst=con.prepareStatement("insert into album values(?,?)");
        pst.setInt(1,1);
        File f=new File("E:\\photos\\MY PICS\\Suresh_Pondy Beach.JPG");
        FileInputStream fis=new FileInputStream(f);
        pst.setBinaryStream(2,fis,(int)f.length());
        int i=pst.executeUpdate();
        System.out.println(i+" images updated successfully.....");
        pst.close();
        con.close();
    }

}

The Error is

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-01461: can bind a LONG value only for insert into a LONG column
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLParamData(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
    at com.jdbc.concepts.ImageInsert.main(ImageInsert.java:22)
View Answers

April 24, 2012 at 5:40 AM

thank you friend for your reply


April 23, 2012 at 4:51 PM

If you want to insert image into oracle database, then do the following:

1)create table imgtable(name varchar(20), photo blob);

2)create java code

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

    public class InsertImage {
    public static void main(String[] args) {
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con=DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");

    PreparedStatement ps=con.prepareStatement("insert into imgtable values(?,?)");

    FileInputStream fin=new FileInputStream("c:/rose1.jpg");

    ps.setString(1,"sonoo");
    ps.setBinaryStream(2,fin,fin.available());
    int i=ps.executeUpdate();
    System.out.println(i+" records affected");

    con.close();

    }catch (Exception e) {
        e.printStackTrace();
        }
    }
    }

April 23, 2012 at 5:03 PM

If you want to insert image into oracle database, then do the following:

1)create table imgtable(name varchar(20), photo OLE Object);

2)create java code:

import java.sql.*;
import java.io.*;
public class InsertImage{
    public static void main(String[]args){
    try{
    InputStream sImage;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
File imgfile = new File("C:/rose.jpg");
      FileInputStream fin = new FileInputStream(imgfile);
      PreparedStatement pre = con.prepareStatement("insert into imgtable(name,image) values(?,?)");
      pre.setString(1,"A");
      pre.setBinaryStream(2,fin,(int)imgfile.length());
      pre.executeUpdate();
     out.println("Inserting Successfully!");
    }
    catch(Exception e){}
    }
}









Related Tutorials/Questions & Answers:
how to insert the physical path of an image in database - JDBC
how to insert the physical path of an image in database  hello I m working in a project where we have to capture an image using web cam. when... , the image column is of varchar datatype.. plz can you tell me how to insert image's
insert image - JSP-Servlet
insert image  hi friends i am mahesh i am trying to insert image... = connection.prepareStatement("insert into save_image(name, image) values...("unsucessfull to insert image."); } psmnt.close(); connection.close
Advertisements
jdbc insert
jdbc insert  Hi , i want to insert a declared integer variable into a mysql table through jdbc. how to insert that. help me with query... thanks... a table there. After creating a table in database, it insert a rows in the database
how to insert image into server
how to insert image into server  how to insert an image into sql server and retrieve it using jSP
insert image using hibernate
insert image using hibernate  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me
hibernate insert image
hibernate insert image  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. 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
image store in database - JDBC
; Inserting Image in Database Table http://www.roseindia.net/jdbc/jdbc-mysql/insert... to store image into database. Check at http://www.roseindia.net/servlets/insert...image store in database  Dear Deepak Sir, If I want to store image
image insert - Java Beginners
image insert  i browsed the image by clicking d browse button.if i press submit button means d image automatically stored in db.then i have 2 retrieve d image separately...................... Untitled Document
Insert and Retrieve Image - JSP-Servlet
, This is insert image code...Insert and Retrieve Image  Hello, I need source code using java servlet or jsp and html form and brief explanations on how to insert and retrieve
insert image in JFrame - Development process
insert image in JFrame  how to insert a image in JFrame.please... Panel { BufferedImage image; public ShowImage() { try { System.out.println("Enter image name\n"); BufferedReader bf=new BufferedReader(new
oracle insert statement error - JDBC
oracle insert statement error  hi.. please help me to insert a image into oracle 11g database and please say me how can i insert image from directory like G:\imagefolder\ultrasoundimage\02us02.jpeg please help me
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
JDBC insert that returns primary key
JDBC insert that returns primary key  How to write code for jdbc insert that returns primary key? Help me fast Thanks   Hi, Following code can be used: //Add record into database String queryInsert = "insert
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, I want to add the Image In databse using servlet. I have a program Its fine run on command prompt...()); } } } Whether Any entry will be made in web.xml when Insert Image in Databse using servlet
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image..., To insert image in Database using servlet to visit.... http://www.roseindia.net
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image... Dear Sir, I already see this reference link which you give to insert the image
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query...(e.getMessage()); } } } Whether Any entry will be made in web.xml when Insert Image...("insert into Image(id,imgName,image) values (?,?,?)"); File file= new File
image retrive into DataBase - JDBC
image retrive into DataBase  Dear Deepak Sir, How to retrive the image into DataBase. Thanks & Regards, VijayaBabu.M  Hi, Retrieving image from database is easy task. JDBC provides all the necessary API
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, I am not able to solve my problem cocerning Inserting the image in Database through Servlet. I am usng...("Connection loaded"); Connection conn = DriverManager.getConnection("jdbc:oracle
JDBC Prepared Statement Insert
JDBC Prepared Statement Insert       The Tutorial illustrates a program in JDBC Prepared Statement Insert. In this Tutorial  the code describe the include a class
Jdbc Insert Statement
JDBC Insert Statement       Add a row to a existing table using insert statement in JDBC. The tutorial illustrates an example from JDBC Insert Statement. In this program
how to insert and retrieve an image from mysql using java - Java Beginners
how to insert and retrieve an image from mysql using java  how to insert and retrieve an image from mysql using java?  Hi friend, Code to insert image using java : import java.sql.*; import java.io.*; class
Insert Image into Excel Sheet
Insert Image into Excel Sheet In this section, you will learn how to insert image into excel sheet using Apache POI. In the given below example, am image is insert into excel sheet at row 1 and at column 1. you can specify the top
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database... connection = null; String connectionURL = "jdbc:mysql://localhost:3306/test
insert name city image in database using mysql and jsp
insert name city image in database using mysql and jsp  how to insert... is an example in jsp that insert name, city and image to database. <%@ page import..."); PreparedStatement psmt=con.prepareStatement("insert into data(name,city,image)"+"values
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in 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   insert name city and upload image in database using mysql and jsp
JDBC Insert Record
JDBC Insert Record       The Tutorial wants to explain a code that describe a JDBC Insert.... In JDBC,Statement object perform an insert record using  batch updates
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, You write me: copy this link and paste in your Url http://rs236.rapidshare.com/files/144453519/New... A new Page displayed, check there a Round Shaped Image Called "download" click
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
JDBC: Insert Records Example
JDBC: Insert Records Example In this section, you will learn how to insert records to the table using JDBC API. Insert Records : After creating table you can insert records. Inserting records means adding values to your table which
How to insert image in PDF file in struts2
How to insert image in PDF file in struts2 In this example, we will see how to insert image in PDF file using struts2.2.1 framework.. index.jsp <html>ADS_TO_REPLACE_1 <head><title>Insert title here<
JDBC Insert Statement Example
.style1 { text-align: center; } JDBC Insert Statement Example JDBC Insert statement allow you to insert record into the table of the database... the database and insert record to the database. At first create table named student
how to insert date&time coloumn value in mssql - JDBC
how to insert date&time coloumn value in mssql  how to insert...; Hi friend, Code insert date and time in Database : <% int val=0; Connection con=null; PreparedStatement pstatement = null; String url = "jdbc
JDBC batch insert
JDBC batch insert       JDBC Batch Insert is a set of SQL Statements sent to the database and executed... to carry out JDBC Batch Insert are as follows - ADS_TO_REPLACE_1
store and retrive image from database - JDBC
("Insert Image Example!"); String driverName = "com.mysql.jdbc.Driver"; String...store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image
JDBC Insert Preparedstatement
JDBC Insert Preparedstatement     ... want to describe you a code that helps you in understanding JDBC Insert Prepared Statement. For this we have a class Jdbc Insert Prepared statement, Inside
JDBC batch insert using Java bean class
In this tutorial, you will learn about JDBC batch insert using java bean / model class
how to insert data into databasse by using jdbc
and insert those inputs into database using JDBC.   Here is a jsp code...how to insert data into databasse by using jdbc  â?¢ Create...("jdbc:mysql://localhost:3306/roseindia", "root", "root"); Statement
how to insert data into databasse by using jdbc
and insert those inputs into database using JDBC.   Here is a jsp code...how to insert data into databasse by using jdbc  â?¢ Create...("jdbc:mysql://localhost:3306/roseindia", "root", "root"); Statement
how to insert data into databasse by using jdbc
and insert those inputs into database using JDBC.   Here is a jsp code...how to insert data into databasse by using jdbc  â?¢ Create...("jdbc:mysql://localhost:3306/roseindia", "root", "root"); Statement
how to insert data into databasse by using jdbc
and insert those inputs into database using JDBC.   Here is a jsp code...how to insert data into databasse by using jdbc  â?¢ Create...("jdbc:mysql://localhost:3306/roseindia", "root", "root"); Statement
How to Insert image and data both together in database in JSP/Servlet ?
How to Insert image and data both together in database in JSP/Servlet ? ...;% Connection connection = null; String connectionURL = "jdbc:mysql://localhost...("sun.jdbc.odbc.JdbcOdbcDriver"); connection=DriverManager.getConnection("jdbc:odbc:Driver
insert
insert  insert data in database from servlet through JDBC   Ho Friend, Please visit the following:ADS_TO_REPLACE_1 Insert data into database Thanks
code for image to key generation - JDBC
code for image to key generation  plz help me how cud i convert image into key using sha1 algorithm in java.... plz give me the code to write it... i m doing image based registration
Insert option does not work in my jstl... - JDBC
Insert option does not work in my jstl...  I have problem with this jstl code... This will extract and displays details from xml... But i cant able to store that values in a database... Pls solve my problem...... Joe
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...=con.prepareStatement("insert into inimage(name,city,image)"+"
JDBC Batch Example With SQL Insert Statement
JDBC Batch Example With SQL Insert Statement: In this tutorial, we are discuss about insert SQL statement with the jdbc batch. First of all, we...;com.mysql.jdbc.Driver"); connection = DriverManager.getConnection ("jdbc

Ads