Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UUID extends org.postgresql.util.PGobject {
- public static final long serialVersionUID = 668353936136517917L;
- public UUID(String s) throws java.sql.SQLException {
- super();
- this.setType("uuid");
- this.setValue(s);
- }
- }
- java.sql.PreparedStatement stmt =
- conn.prepareStatement("UPDATE t SET uid = ? WHERE id = 1");
- stmt.setObject(1, new UUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"));
- stmt.executeUpdate();
- Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "foo", "bar");
- con.setAutoCommit(false);
- Statement stmt = con.createStatement();
- stmt.addBatch("create table foo (id integer, data varchar(100))");
- stmt.addBatch("insert into foo values (1, 'one')");
- stmt.addBatch("insert into foo values (2, 'two')");
- stmt.addBatch("update foo set data = 'one_other' where id = 1");
- stmt.executeBatch();
- con.commit();
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>8.4-702.jdbc4</version>
- </dependency>
- pstm.setObject(1, guid); //where pstm is a PreparedStatement and guid is a UUID
- //where rs is a ResultSet
- UUID myGuid = (UUID) rs.getObject("my_uuid_column_name");
- java.util.UUID uuid = java.util.UUID.randomUUID();
- …
- preparedStatement.setObject( nthPlaceholder++, uuid ); // Pass UUID to database.
Add Comment
Please, Sign In to add comment