Use clob as a large object in Java

Source: Internet
Author: User

Private int adddata (string Mac, string Sn, string content ){
Int flag = 0;
Connection conn = NULL;
Preparedstatement PS = NULL;
Resultset rs = NULL;
Conn = connectionutil. getconnection ();
Try {
String SQL = "insert into ecs_sfis_testlog (log_id, log_mac, log_sn, log_content, log_create_time) values (ecs_sfis_testlog_id.nextval, '" + Mac + "','"
+ Sn + "', empty_clob (), sysdate )";
Conn. setautocommit (false );
PS = conn. preparestatement (SQL );
Flag = ps.exe cuteupdate ();
SQL = "select log_content from ecs_sfis_testlog where log_mac = '" + Mac
+ "'For update ";
Resultset rs2 = ps.exe cutequery (SQL );
If (rs2.next ()){
Clob = rs2.getclob (1 );
Bufferedwriter BW = new bufferedwriter (clob
. Setcharacterstream (clob. Length ()));
Bw. Write (content );
Bw. Close ();
}
Conn. Commit ();
Conn. setautocommit (true );
Connectionutil. closeresultset (RS );
Connectionutil. closepreparedstatement (PS );
Connectionutil. closeconnection (conn );
} Catch (sqlexception e ){
E. printstacktrace ();
Log. writeexception (new date () + "/N" + E. getmessage ());
} Catch (ioexception e ){
E. printstacktrace ();
Log. writeexception (new date () + "/N" + E. getmessage ());
}
Return flag;
}

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.