Question: How to insert clob data??



Share on Google+Share on Google+

How to insert clob data??
2 Answer(s)      5 years and a month ago
Posted in : JDBC

Can any one tell me in details how to populate clob column in a table using sql??I tried simple sql statements but found out that simple sql statements won't allow more than 4000 characters but I need to insert more than 4000 characters.I have heard that clob fields can hold 4 gb of data and need pl/sql to avail that feature.Can any one tell me how to create pl/sql blocks and statements.I want to insert value of a textarea into clob column of a table.So please some one tell me what should I do??

View Answers

April 12, 2012 at 1:50 PM

No it is not the way I actually want.I need the pl/sql code.Actually I am fetching the data from a form page.I can't use a file to fetch the data.All I need is to get the data from text area and then insert the data into table through pl/sql code.

April 12, 2012 at 12:52 PM

In MySql database,TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT can be taken as CLOB type. Here we have used longtext datatype.

1)create a table article in database.

              CREATE TABLE `article` (                 
               `ID` int(11) NOT NULL auto_increment,  
               `Subject` varchar(256) NOT NULL,       
               `Body` longtext,                       
               PRIMARY KEY  (`ID`)                    

2)Here is the java code:

import java.sql.*;
class  InsertClobData
    public static void main(String[] args){
        Connection con = null;

  String fileName = "c:/data.dat";
  try {
  con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/test", "root", "root");
  String clobData = getClobDataAsString(fileName);
  PreparedStatement ps = con.prepareStatement("insert into article(subject, body)values (?, ?)");
  ps.setString(1, fileName);
  ps.setString(2, clobData);
  System.out.println("Clob data is instered successfully");
  catch (Exception e) {

  public static String getClobDataAsString(String filename) throws Exception {
    InputStream is = null;
    try {
      is = new FileInputStream(filename);
      int BUFFER_SIZE = 1024;
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      int length;
      byte[] buffer = new byte[BUFFER_SIZE];
      while ((length = != -1) {
        output.write(buffer, 0, length);
      return new String(output.toByteArray());
    } finally {


Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu


Advertisement null