Convert string to clob in Oracle

Source: Internet
Author: User

Convert string to clob in the project

/**

* Convert string to clob.
* @ Author zhaohr
* @ Param sort
* @ Throws classnotfoundexception
* @ Throws sqlexception
*/
@ Suppresswarnings ("UNUSED ")
Public int insertsortwithstr2clob (sort) throws classnotfoundexception, sqlexception {
// Todo auto-generated method stub
Drivermanager. registerdriver (New oracledriver ());
String url = "JDBC: oracle: thin :@ localhost: 1521: orcl ";
String user = "shopguide ";
String Pwd = "shopguide ";
String text = sort. getinfo ();
Connection conn = drivermanager. getconnection (URL, user, PWD); // get the connection object
String SQL = "insert into website_sort (ID, name, sort_level, parent_sort, arrange, isshow, pic1, info, remark, company_id, update_date, update_user) values (?,?,?,?,?,?,?,?,?,?,?,?) ";
Preparedstatement stmt = conn. preparestatement (SQL); // load an SQL statement
Reader clobreader = new stringreader (text); // converts text into a stream
Stmt. setint (1, sortsequence. nextintvalue ());
Stmt. setstring (2, sort. getname ());
Stmt. setstring (3, sort. getsortlevel ());
Stmt. setint (4, sort. getparentsort ());
Stmt. setstring (5, sort. getarrange ());
Stmt. setstring (6, sort. getisshow ());
Stmt. setint (7, sort. getpic1 ());
Stmt. setcharacterstream (8, clobreader, sort. getinfo (). Length (); // replace? Convert string to clob
Stmt. setstring (9, sort. getremark ());
Stmt. setstring (10, sort. getcompanyid ());
Stmt. setdate (11, new java. SQL. Date (sort. getupdatedate (). gettime ()));
Stmt. setstring (12, sort. getupdateuser ());
Int num = stmt.exe cuteupdate (); // Execute SQL
Stmt. Close ();
Conn. Close ();
Return num;
}

Related Article

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.