-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Trying to store blob type imge file in oracle 11g data base
PostPosted: Tue Oct 15, 2013 11:14 am 
Newbie

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;
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.