Java: How to insert CLOB into oracle database

前端 未结 10 1285
情话喂你
情话喂你 2020-12-03 03:32

I need to write an XML file content into oracle database where the column is of CLOB datatype. How will I do that?

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 04:14

    passing the xml content as string.

    table1 
    
    ID   int
    XML  CLOB
    
    
    
    import oracle.jdbc.OraclePreparedStatement;
    /*
    Your Code
    */
     void insert(int id, String xml){
        try {
            String sql = "INSERT INTO table1(ID,XML) VALUES ("
                    + id
                    + "', ? )";
            PreparedStatement ps = conn.prepareStatement(sql);
            ((OraclePreparedStatement) ps).setStringForClob(1, xml);
            ps.execute();
            result = true;
            } catch (Exception e) {
            e.printStackTrace();
        }
      }
    

提交回复
热议问题