Here is the info:
CLOB
setClob()
So my question is how to create an object CLOBfrom this line so that I can use the method setClob().
Thanks in advance, Naveen
If you want to write a String column for CLOB just use PreparedStatement.setString.
PreparedStatement.setString
If you want to know how to create a CLOB from String, this is it
Clob clob = connection.createClob(); clob.setString(1, str);
You can create clob from the connection object as follows
Connection con = null;// write code to make a connection object Clob clob = con.createClob(); String str = "this is a stirng"; clob.setString(1, str ); PreparedStatement ps = null;// write code to create a prepared statement ps.setClob(4, clob);
:
//alternative way String str = "this is a stirng"; ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes()); InputStreamReader inputStreamReader = new InputStreamReader(inputStream); int parameterIndex = 1; PreparedStatement ps = null;// write code to create a prepared statement ps.setClob(parameterIndex, inputStreamReader);
CLOB . , .setString(), . ORACLE jdbc, , CLOB INPUT, , .
INSERT INTO MY_TABL (NUM_COL, VARC_COL, VARC_COL, TS_COL, CLOB_COL) VALUES(?,?,?,?,?);
, CLOB_COL CLOB , .setString(5) 5 - .
Clob, "setString" , : "setString 32766 "
connection.createClob, :
java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.createClob()Ljava/sql/Clob;
, , CLOB java throwing, ( setCharacterStream setClob)
/ ( a_horse_with_no_name)
StringReader reader = new StringReader(userAbout); PreparedStatement insertClob = dbCon.prepareStatement("UPDATE user_data SET user_about=? WHERE user_id=?"); insertClob.setCharacterStream(1, reader, userAbout.length()); insertClob.setInt(2,userId);
, Oracle java-, db. .
, oracle.sql.CLOB
create table test_clob ( c clob ); create or replace and compile java source named java_clob_insert as import java.sql.Connection; import java.sql.PreparedStatement; import oracle.sql.CLOB; import java.io.Writer; public class JavaClobInsert { public static void doInsert () { try { //create the connection and statement Connection oracleConn = (new oracle.jdbc.OracleDriver()).defaultConnection(); String stmt = "INSERT INTO test_clob values (?)"; PreparedStatement oraclePstmt = oracleConn.prepareStatement(stmt); //Imagine we have a mysql longtext or some very long string String s = ""; for (int i = 0; i < 32768; i++) { s += i % 10; } //Initialise the Oracle CLOB CLOB clob; clob = CLOB.createTemporary(oracleConn, true, CLOB.DURATION_CALL); //Good idea to check the string is not null before writing to clob if (s != null) { Writer w = clob.setCharacterStream( 1L ); w.write(s); w.close(); oraclePstmt.setClob(1, clob); } else { oraclePstmt.setString(1, ""); } //clean up oraclePstmt.executeUpdate(); oracleConn.commit(); oraclePstmt.close(); oracleConn.close(); } catch (Exception e) { e.printStackTrace(); } } } / create or replace procedure clob_insert as language java name 'JavaClobInsert.doInsert()'; / begin clob_insert; end; / select * from test_clob;
...
PreparedStatement, stmt, stmt.setString(colIndex, value) CLOB.
stmt
stmt.setString(colIndex, value)
.
, :
ORA-22275: invalid LOB locator
, , - , value . Oracle, MSSQL DB2.
value
, , ,
if (value == null) { stmt.setNull(colIndex, java.sql.Types.CLOB); } else { stmt.setString(colIndex, value); }
!
Source: https://habr.com/ru/post/1529622/More articles:Does OBJC_ASSOCIATION_ASSIGN mean atomic or non-atomic? - objective-cUnable to post space in database: postgreSQL and Codeigniter - phpWhat is the advantage of using gradle in Android development? - androidAssociative array in javascript using the / tuple pair as a multi-valued key / index - javascriptЗамена только определенной части объекта JSON - c#using CLOB in java throwing exception - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1529624/authentication-to-box-in-a-c-desktop-application-using-the-box-windows-sdk-v2-library&usg=ALkJrhgdndrDVjrB_fFtxIIp4n4YHVNmQQRunning code execution in a global space compared to a function in Javascript - javascriptHow to import several databases at once through PhpMyAdmin? - mysqlDB2 JDBC Create clob error - javaAll Articles