-1

when I'm trying to insert blob in database having more than 4000 characters I'm getting fallowing error can anyone help on this.is there any way other than procedures to insert data :

Error report -

  SQL Error: ORA-01704: string literal too long
  01704. 00000 -  "string literal too long"
  *Cause:    The string literal is longer than 4000 characters.
  *Action:   Use a string literal of at most 4000 characters.
           Longer values may only be entered using bind variables
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
  • have you checked the datatype of your column? – John Kane Jul 16 '18 at 12:56
  • Please update your question with a [MCVE] including the code you are currently using to insert the blob (that generated the error). – MT0 Jul 16 '18 at 12:56
  • @JohnKane The error is on a string literal's length exceeds 4000 characters (which is its limit) and not on the column. Without more details of how the OP is using the string literal it is almost impossible to answer. – MT0 Jul 16 '18 at 12:58
  • iam not using any code through query iam insert – Divya Reddy Jul 16 '18 at 13:03
  • below is query used for inserting into database – Divya Reddy Jul 16 '18 at 13:04
  • INSERT INTO AUTONOMOUS_VENDOR_MODEL (VENDOR_NAME,V_MODEL,VENDOR_API_DEFINITION) VALUES('Versa','CPE', rawtohex (json data here)); – Divya Reddy Jul 16 '18 at 13:05
  • @DivyaReddy Please do not add code in comments - [edit your question](https://stackoverflow.com/posts/51362329/edit). Also, why have you tagged Java? If you are using Java then please include the relevant Java code - if you are not using Java (or it is not immediately relevant to this question) then please delete the tag. – MT0 Jul 16 '18 at 13:29

1 Answers1

0

Instead of setString use setCharacterStream (for instance). Of course assuming you are already using a PreparedStatement:

try (PreparedStatement stmt = conn.prepareStatement(someSql)) {
    String large = String.format("%-4001s", "xxx");
    StringReader reader = new StringReader(large);
    stmt.setCharacterStream(1, reader, large.length());
    stmt.setLong(2, someId);
    int updateCount = stmt.executeUpdate();
}
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138