The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

problem creating BLOB object String object and store it into the database

Posted by supal chowdhury on December 07, 2000 at 12:25 AM

please help to solve my problem to store String object into Database table having col of type BLOB.

I have written this code.Change the Drivermanager.getConnection() method's accordingly
It is giving SQLException during run time.
Check it and solve it.
mail me to supalc@macmetit.com

The ins_blob procedure contains the insert statement to the table.

Table creatinon sql script:
=============
create table
files_org(val number, blb BLOB);


Create Procedure follows:
=========
Create OR Replace procedure ins_blob(p_id in number,p_content BLOB)

as

l_blob blob;

begin

insert into files_org values( p_id, empty_blob() )

returning content into l_blob;

commit;

--dbms_lob.writeappend ( l_blob,length(content), content);

update files_org set content = p_content where file_id = p_id;

commit;

end;


The Java Code follows:
=======
import oracle.jdbc.driver.*;
import oracle.sql.*;

public class tst
{

public static void main(String[] args) throws Exception
{

try
{
java.sql.Connection con = null;
Class.forName("oracle.jdbc.driver.OracleDriver");//Registered the dr
iver
con = DriverManager.getConnection("jdbc:oracle:thin:@10.1.1.2:1521:M
ACI","scott","tiger");

/*********/
String s = "Supal";

oracle.sql.BLOB BL = new oracle.sql.BLOB((OracleConnection)con,s.getBytes());
String sQuery = "begin " + "ins_blob" + "(?,?);end;";
OracleCallableStatement rcProc = (OracleCallableStatement)con.prepar
eCall(sQuery);
rcProc.setInt(1,563);
rcProc.setBLOB(2,BL);
rcProc.execute();

System.out.println("Insert successfully");
}
catch(SQLException e)
{
System.out.println("Exception occured: "+e);
}
catch(Exception e1)
{
System.out.println("Exception occured 1 : "+e1);
}
/***********/
}


SQLException is :
=======
Exception occured: java.sql.SQLException: ORA-24812: character set conversion to
or from UCS2 failed
ORA-06512: at "SCOTT.INS_BLOB", line 11
ORA-06512: at line 1





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us