• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to update clob field in oracle

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could somebody tell me how to update clob field in oracle 8.1.7? I use preparestatement.setString, and get "data size too big" error.
Thanks a lot.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a method I use to update Clob.
public void updateClob(String updateString, int rowID, Connection con)
{
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

Clob clob = null;
try
{
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT CLOB FROM YOUR_TABLE WHERE ID =" + rowID + " FOR UPDATE OF CLOB");
if(rs.next())
{
clob = rs.getClob("CLOB");
}

OutputStream os = ((oracle.sql.CLOB) clob).getAsciiOutputStream();

byte[] b = updateString.getBytes("ASCII");

os.write(b);
os.flush();
os.close();

pstmt = con.prepareStatement("UPDATE YOUR_TABLE SET CLOB = ? WHERE ID = " + rowID);

pstmt.setClob(1, clob);
pstmt.executeUpdate();
}
catch(Exception e)
{
//log error
}
finally
{
try
{
pstmt.close();
rs.close();
stmt.close();
}
catch(Exception e)
{
//log error
}
}
}
[ September 16, 2002: Message edited by: Patrick McDowell ]
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be interested in these Oracle resources to help you:
Oracle9i JDBC Developer's Guide and Reference( great tutorial using Oracle/JDBC )
loads of Oracle JDBC sample code
Jamie
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!