chundru suresh
Insert an Image in JDBC
3 Answer(s)      4 years and 5 months ago
Posted 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)

Ads

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
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
Advertisements
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
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 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
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
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
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 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
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 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
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
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 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
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
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
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
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 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 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 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

Ads

Advertisement