Built-in object Clob read from a column value of a character large object Clob type taken from a database table

Source: Internet
Author: User

1  PackageReadclobdemo.bao;2 3 Importjava.io.IOException;4 ImportJava.io.Reader;5 ImportJava.sql.Clob;6 Importjava.sql.Connection;7 Importjava.sql.PreparedStatement;8 ImportJava.sql.ResultSet;9 Importjava.sql.SQLException;Ten  One ImportJdbcutil.bao.JdbcUtil; A  -  Public classReadclobdemo { -  the     /** - Clob is used to store large amounts of character data, and the main function of the program is to get the Clob field from the database through JDBC and convert it to IO for reading. - so first get the Clob field through the query statement, then get the CLOB from the result set and convert it to Oracle.sql.CLOB type for write operation -      * @throwsIOException +      */ -      +      A      at     /*CREATE TABLE "HR". " Clob_1 " - ("ID" number (*,0), - "Clob_text" CLOB - ) SEGMENT CREATION IMMEDIATE*///CREATE table Clob_1 in Oracle; -      -      Public Static voidReadclob (intIdthrowsioexception{ in          -          toConnection conn=NULL; +PreparedStatement patst=NULL; -ResultSet rs=NULL; theString sql= "SELECT * from Clob_1 where id=?"; *         Try { $Conn=jdbcutil.getconnection ();//connection to a database by obtaining the database connection interface allocated in the data connection pool JdbcutilPanax Notoginsengpatst=conn.preparestatement (SQL); -Patst.setint (1, id); theRs=patst.executequery ();//returns the result set; +              A             if(Rs.next ()) { the                  +Clob Clob=rs.getclob ("Clob_text");//The Clob object is valid during the transaction to which it was created -Reader rd=Clob.getcharacterstream (); $                  $                 Char[] chars =New Char[1024];//define a character array -  -                    intLength=0; the  -System.out.print ("Clob_text:");Wuyi                  //read return int byte value via IO stream to char type until no byte, return-1 the                     while((Length=rd.read (chars))! =-1) {   -  Wu                     if(length==1024){ -  About System.out.print (chars); $  -}Else{ -  -System.out.print (NewString (chars,0,length));//A character array that is not 1024 long enough to display only strings with values A  +                    } the                  -              } $                  the                  the           } the              the}Catch(SQLException E1) { - e1.printstacktrace (); in}finally{ theJdbcutil.free (RS, PATST, conn);//call the free method defined by Jdbcutil to close each interface; the         } About          the          the     } the      Public Static voidMain (string[] args)throwsIOException { +          -Readclob (1); the                 Bayi     } the  the}

Built-in object Clob read from a column value of a character large object Clob type taken from a database table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.