Joined: Tue Oct 15, 2013 10:39 am Posts: 1
|
Hi, attempting to insert a blob image into an oracle11g db with ojdbc5 & 6 jar file.But in both case getting the following error when posting:Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatementWrapper.setBinaryStream(ILjava/io/InputStream;J)V programs:- 1.POJO:-Photo1.java import java.sql.Blob; public class Photo1 { private String id; private Blob photo; public String getId() { return id; } public void setId(String id) { this.id = id; } public Blob getPhoto() { return photo; } public void setPhoto(Blob photo) { this.photo = photo; } } 2.mapping file:-Photo1.hbm.xml <hibernate-mapping package="com.lara"> <class name="Photo1" table="Snap"> <id name="id" column="P_Id"/> <property name="photo" /> </class> </hibernate-mapping> 3.config file:-hibernate.cfg.xml <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.username">system</property> <property name="hibernate.connection.password">pankaj</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property> <property name="hibernate.hbm2ddl.auto">create-drop</property> <mapping resource="com/lara/Photo1.hbm.xml" /> </session-factory> </hibernate-configuration> 4.Client java program:- package com.lara;
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.sql.Blob;
import javax.sql.rowset.serial.SerialBlob;
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder;
public class Manager1 { public static void main(String[] args) throws Exception { Photo1 p1=new Photo1(); p1.setId("p102"); Blob blob = new SerialBlob(getPhotoContent()); p1.setPhoto(blob); Configuration c1=new Configuration(); c1.configure(); ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(c1.getProperties()).buildServiceRegistry(); SessionFactory sf=c1.buildSessionFactory(sr); Session s1=sf.openSession(); s1.beginTransaction(); s1.save(p1); s1.getTransaction().commit(); s1.flush(); s1.close(); System.out.println("done"); } private static byte[] getPhotoContent() throws Exception { byte[] x = null; File f1 = new File("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg"); x = new byte[(int)f1.length()]; FileInputStream fin = new FileInputStream(f1); BufferedInputStream bin = new BufferedInputStream(fin); bin.read(x); bin.close(); fin.close(); return x; } }
|
|