Skip to content

Instantly share code, notes, and snippets.

View brunkb's full-sized avatar

Ben Brunk brunkb

  • Minnesota
View GitHub Profile
Class.forName(JDBC_DRIVER)
Connection conn = DriverManager.getConnection(creds.url, creds.userName, creds.password)
String updateTableSQL = "update Book set title=? where id=?"
PreparedStatement preparedStatement = conn.prepareStatement(updateTableSQL)
preparedStatement.setString(1, title)
preparedStatement.setInt(2, id)
preparedStatement.executeUpdate()
Class.forName(JDBC_DRIVER)
Connection conn = DriverManager.getConnection(url, userName, password)
String insertTableSQL = "INSERT INTO BOOK (ID, TITLE, AUTHOR_ID) VALUES (?,?,?)"
Map insertTest = [(Book.BOOK.ID): 7,
(Book.BOOK.AUTHOR_ID): 1,
(Book.BOOK.TITLE): "Coding in JDBC"]
PreparedStatement preparedStatement = conn.prepareStatement(insertTableSQL)
preparedStatement.setInt(1, insertTest[(Book.BOOK.ID)])
select b.id, b.title, a.first_name, a.last_name from
Book b inner join
Author a on
b.author_id = a.id;
String sql = "””INSERT INTO AUTHOR (ID, FIRST_NAME, LAST_NAME)
VALUES (:id, :firstName, :lastName)"””
Map parameters = [id: 1337, firstName: “Pauly”, lastName: "McCoy"]
// jdbcTemplate is an autowired property
jdbcTemplate.update(sql, parameters)
create.update(Book.BOOK)
.set(Book.BOOK.TITLE, "A Brief Introduction to JOOQ")
.where(Book.BOOK.ID.equal(2))
.execute()
Result<Record> result = create.select().from(Book.BOOK).fetch()
@brunkb
brunkb / jooq_insert.groovy
Last active September 27, 2015 03:31
JOOQ
create.insertInto(Book.BOOK)
.set(Book.BOOK.ID, 5)
.set(Book.BOOK.AUTHOR_ID, 1)
.set(Book.BOOK.TITLE, "The Idiot's Guide to Programming")
.execute()
@brunkb
brunkb / hibernate_entity_fragment.sql
Created June 8, 2015 18:33
Example Hibernate Annotations
@Lob
@Column(name = "DATA")
private String data;
@brunkb
brunkb / clob_insert1.sql
Created June 8, 2015 18:30
Example of inserting JSON via SQL
insert into myclobs (data, date_created) values (‘[{
"_id": "556e52fc21aa6202ee1aac18",
"index": 0,
"guid": "dd60b0a8-2bb8-4dae-83b4-1940b2e47f9c",
"isActive": false,
"balance": "$3,616.96",
"picture": "http://placehold.it/32x32",
"age": 40,
"eyeColor": "blue",
"name": "Mayra Stevenson",
@brunkb
brunkb / select_inside_clob.sql
Created June 8, 2015 18:29
Oracle 12 Dotted notation for selecting within CLOB
SELECT data.eyeColor FROM myclobs;