Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use setClob() in PreparedStatement inJDBC

Tags:

java

Here are the info:

  1. I have a String
  2. I want to insert a record in a table with the String in a column whose datatype is CLOB.
  3. I would like to use setClob() method of the preparedstatement.

So my question is how to create a Clob object from this String so that I can use setClob() method.

Thanks in advance, Naveen

like image 956
user3369905 Avatar asked Mar 02 '14 04:03

user3369905


People also ask

What does execute update method of PreparedStatement interface returns?

executeUpdate. Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT , UPDATE or DELETE ; or an SQL statement that returns nothing, such as a DDL statement.

Which method is used to create prepare statement?

Creating a PreparedStatement You can create an object of the PreparedStatement (interface) using the prepareStatement() method of the Connection interface. This method accepts a query (parameterized) and returns a PreparedStatement object.


1 Answers

If you want to write a String to CLOB column just use 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);
like image 53
Evgeniy Dorofeev Avatar answered Oct 20 '22 22:10

Evgeniy Dorofeev