
The following example with demonstrate how to handle the large datasets in the queries. BLOB (Binary Large Objects ) and CLOB(Character large objects) are special datatypes and can hold the large chunks of data in form of objects or text. Blob and Clob objects persist the data of the objects into the database as a stream or as a Java array
package com.visualbuilder; import java.io.BufferedReader; import java.io.FileReader; import java.sql.Clob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import javax.sql.rowset.serial.SerialClob;
public class BlobExample { public static void main(String[] args) { try { /** Loading the driver*/ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); /** Getting Connection*/ Connection con = DriverManager.getConnection("jdbc:odbc:MyDsn","scott","tiger"); System.out.println("Connection established"); /** Creating Statement*/ PreparedStatement pst = con.prepareStatement("insert into visualbuilder(id,name,description)values(?,?,?)"); pst.setInt(1,5); pst.setString(2,"VisualBuilder");
// Create a big CLOB value...
StringBuffer buffer = new StringBuffer(500000); while (buffer.length() < 500000) { buffer.append("This is the ClobExample"); } String clobValue = buffer.toString(); pst.setString(3, clobValue); int i= pst.executeUpdate(); System.out.println("Record Inserted"); pst.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } }
Output is:- Connection established Record Inserted | |
Java Discussion
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin
- - Java opportunities
- - Struts


