JDBC Learning Note (iii) Read and write large text data

Source: Internet
Author: User

First, using JDBC to insert large text data into the database

String sql = "INSERT into MY_CLOB values (null,?)"  =new File ("D:\\baidunetdiskdownload\\mysql\\jdbc.sql"New BufferedReader (new  FileReader (f));  Ps.setcharacterstream (1, Reader, f.length ()); int res = ps.executeupdate (); System.out.println (res); Reader.close ();


Second, read large text data from the database to write to the file

Method One: Save the data directly into the string

String Big_text = rs.getstring ("Bit_text"new File ("D:\\baidunetdiskdownload\\mysql\\jdbc.bak.sql "new  FileWriter (f); Wt.write (Big_text); Wt.close ();

Mode two: Get input stream read data through ResultSet object RS, create output stream write to file

Reader rd = Rs.getcharacterstream ("Bit_text"); New File ("D:\\baidunetdiskdownload\\mysql\\jdbc.bak.sql"new  FileWriter (f); Char New Char [1024x768];
int i = 0;
while ((i = rd.read (buff))! =-1)
{
0, I);
}
Wt.close ();
Rd.close ();

Method Three, get the input stream through the Clob object

CB = Rs.getclob ("Bit_text");
Reader rd = Cb.getcharacterstream (); New File ("D:\\baidunetdiskdownload\\mysql\\jdbc.bak.sql");
New FileWriter (f);
Char New Char [1024x768];
int i = 0;
while ((i = rd.read (buff))! =-1)
{
0, I);
}
Wt.close ();
Rd.close ();

JDBC Learning Note (iii) Read and write large text data

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.