List of usage examples for java.sql Connection createClob
Clob createClob() throws SQLException;
Clob
interface. From source file:com.groupon.odo.proxylib.SQLService.java
/** * Converts the given string to a clob object * * @param stringName string name to clob * @param sqlConnection Connection object * @return Clob object or NULL/*from w w w. ja v a2s . co m*/ */ public Clob toClob(String stringName, Connection sqlConnection) { Clob clobName = null; try { clobName = sqlConnection.createClob(); clobName.setString(1, stringName); } catch (SQLException e) { // TODO Auto-generated catch block logger.info("Unable to create clob object"); e.printStackTrace(); } return clobName; }
From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java
@Test public void testTypes() throws Exception { Connection conn = new MyProxy(); try {//from www .j a v a 2 s . com try { conn.createBlob(); } catch (Exception e) { } try { conn.createClob(); } catch (Exception e) { } try { conn.createNClob(); } catch (Exception e) { } try { conn.createSQLXML(); } catch (Exception e) { } try { conn.createStruct("java.lang.String", new String[] { "hello" }); } catch (Exception e) { } try { conn.createArrayOf("java.lang.String", new String[] { "hello", "world" }); } catch (Exception e) { } } finally { JdbcUtil.closeQuietly(conn); } }
From source file:com.webpagebytes.cms.local.WPBLocalDataStoreDao.java
private int buildStatementForInsertUpdate(Object obj, Set<String> ignoreFields, PreparedStatement preparedStatement, Connection connection) throws SQLException, WPBSerializerException { Class<? extends Object> kind = obj.getClass(); Field[] fields = kind.getDeclaredFields(); int fieldIndex = 0; for (int i = 0; i < fields.length; i++) { Field field = fields[i];/*from w w w . j ava 2 s . c om*/ field.setAccessible(true); boolean storeField = (field.getAnnotation(WPBAdminFieldKey.class) != null) || (field.getAnnotation(WPBAdminFieldStore.class) != null) || (field.getAnnotation(WPBAdminFieldTextStore.class) != null); if (storeField) { String fieldName = field.getName(); if (ignoreFields != null && ignoreFields.contains(fieldName)) { continue; } fieldIndex = fieldIndex + 1; Object value = null; try { PropertyDescriptor pd = new PropertyDescriptor(fieldName, kind); value = pd.getReadMethod().invoke(obj); } catch (Exception e) { throw new WPBSerializerException("Cannot get property value", e); } if (field.getType() == Long.class) { Long valueLong = (Long) value; if (valueLong != null) { preparedStatement.setLong(fieldIndex, valueLong); } else { preparedStatement.setNull(fieldIndex, Types.BIGINT); } } else if (field.getType() == String.class) { String valueString = (String) value; if (field.getAnnotation(WPBAdminFieldStore.class) != null || field.getAnnotation(WPBAdminFieldKey.class) != null) { if (valueString != null) { preparedStatement.setString(fieldIndex, valueString); } else { preparedStatement.setNull(fieldIndex, Types.VARCHAR); } } else if (field.getAnnotation(WPBAdminFieldTextStore.class) != null) { if (valueString != null) { Clob clob = connection.createClob(); clob.setString(1, valueString); preparedStatement.setClob(fieldIndex, clob); } else { preparedStatement.setNull(fieldIndex, Types.CLOB); } } } else if (field.getType() == Integer.class) { Integer valueInt = (Integer) value; if (valueInt != null) { preparedStatement.setInt(fieldIndex, valueInt); } else { preparedStatement.setNull(fieldIndex, Types.INTEGER); } } else if (field.getType() == Date.class) { Date date = (Date) value; if (date != null) { java.sql.Timestamp sqlDate = new java.sql.Timestamp(date.getTime()); preparedStatement.setTimestamp(fieldIndex, sqlDate); } else { preparedStatement.setNull(fieldIndex, Types.DATE); } } } } return fieldIndex; }
From source file:org.apache.eagle.alert.metadata.impl.JdbcMetadataHandler.java
private OpResult executeUpdate(Connection connection, String query, String key, String value) throws SQLException { OpResult result = new OpResult(); PreparedStatement statement = null; try {//from w w w. j a v a 2 s . c o m statement = connection.prepareStatement(query); Clob clob = connection.createClob(); clob.setString(1, value); statement.setClob(1, clob); statement.setString(2, key); int status = statement.executeUpdate(); LOG.info("update {} with query={}", status, query); } finally { if (statement != null) { statement.close(); } } return result; }
From source file:org.kawanfw.test.api.client.InsertAndUpdateClobTestNew.java
public void updateclob(Connection connection, File file) throws Exception { PreparedStatement prepStatement = null; String sql = "update documentation set " + " item_doc = ? " + " where item_id >= ?"; prepStatement = connection.prepareStatement(sql); Clob clob = connection.createClob(); Writer writer = null;/*ww w . j a v a 2 s .com*/ Reader reader = null; try { reader = new BufferedReader(new FileReader(file)); writer = clob.setCharacterStream(1); IOUtils.copy(reader, writer); int i = 1; prepStatement.setClob(i++, clob); prepStatement.setInt(i++, 1); prepStatement.executeUpdate(); // Close and free are important to delete temp files prepStatement.close(); clob.free(); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(writer); } }
From source file:org.xsystem.sql2.dml.DmlCommand.java
Clob setClob(Connection con, String data) throws SQLException { Clob myClob = con.createClob(); Writer wr = myClob.setCharacterStream(0); try {// ww w . j a va 2s. c o m wr.write(data); wr.flush(); return myClob; } catch (IOException ex) { throw new SQLException(ex); } finally { Auxilary.close(wr); } }