8 Ağustos 2019 Perşembe

JDBC Clob Arayüzü

getSubString metodu
Şöyle yaparız.
String sql = "select id, data from mytable";
List< Object[] > results = getEntityManager().createNativeQuery(sql).getResultList();

Clob clob = (Clob)result[1];
String value = clob.getSubString(1, (int) clob.length());
setCharacterStream Sınıfı
Şöyle yaparız.
java.sql.Connection con;
javax.xml.bind.Marshaller marshaller;

Clob xmlClob = con.createClob();
try {
  try (Writer xmlClobWriter = xmlClob.setCharacterStream(1)) {
    m.marshal(jaxbObject, xmlClobWriter);
  } // xmlClobWriter.close();
  try (PreparedStatement stmt=con.prepareStatement("INSERT INTO table (xml) values(?)")){
    stmt.setClob(1, xmlClob);
    stmt.executeUpdate();
  }
} finally {
  xmlClob.free();
}

Hiç yorum yok:

Yorum Gönder