Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UPDATE table SET log=? where id=?
- UPDATE table SET log=log||?||chr(10) where id=?
- java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
- import oracle.jdbc.OracleDriver;
- import java.sql.*;
- import java.io.ByteArrayInputStream;
- public class JDBCTest {
- // How much test data to generate.
- public static final int SIZE = 8192;
- public static void main(String[] args) throws Exception {
- // Generate some test data.
- byte[] data = new byte[SIZE];
- for (int i = 0; i < SIZE; ++i) {
- data[i] = (byte) (64 + (i % 32));
- }
- ByteArrayInputStream stream = new ByteArrayInputStream(data);
- DriverManager.registerDriver(new OracleDriver());
- Connection c = DriverManager.getConnection(
- "jdbc:oracle:thin:@some_database", "user", "password");
- String sql =
- "DECLAREn" +
- " l_line CLOB;n" +
- "BEGINn" +
- " l_line := ?;n" +
- " UPDATE table SET log = log || l_line || CHR(10) WHERE id = ?;n" +
- "END;n";
- PreparedStatement stmt = c.prepareStatement(sql);
- stmt.setAsciiStream(1, stream, SIZE);
- stmt.setInt(2, 1);
- stmt.execute();
- stmt.close();
- c.commit();
- c.close();
- }
- }
Add Comment
Please, Sign In to add comment