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