Advertisement
Guest User

Untitled

a guest
Nov 12th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package com.squareup.JooqTest;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.time.OffsetDateTime;
  6. import jooqtest.tables.records.T1Record;
  7. import jooqtest.tables.records.T2Record;
  8. import org.jooq.DSLContext;
  9. import org.jooq.Field;
  10. import org.jooq.conf.RenderNameStyle;
  11. import org.jooq.conf.Settings;
  12. import org.jooq.impl.DSL;
  13.  
  14. import static jooqtest.tables.T1.T1;
  15. import static jooqtest.tables.T2.T2;
  16.  
  17. public class App {
  18. public static void main(String[] args) throws Exception {
  19. App app = new App();
  20. app.run();
  21. }
  22.  
  23. public void run() throws Exception {
  24. Settings settings = new Settings();
  25. settings.setRenderNameStyle(RenderNameStyle.AS_IS);
  26. settings.withRenderSchema(false);
  27.  
  28. int now = (int) OffsetDateTime.now().toEpochSecond();
  29.  
  30. try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/jooqtest", "root", "")) {
  31. DSLContext jooq = DSL.using(conn, settings);
  32.  
  33. jooq.truncate(T1).execute();
  34. jooq.truncate(T2).execute();
  35.  
  36. jooq.insertInto(T1).set(T1.ID, 1).set(T1.DATE, now).execute();
  37.  
  38. T1Record row1 = jooq.selectFrom(T1).fetchOne();
  39. Field[] fields = row1.fields();
  40.  
  41. jooq.insertInto(T2)
  42. .set(fields[0], row1.getValue(0))
  43. .set(fields[1], row1.getValue(1)).execute();
  44.  
  45. T2Record row2 = jooq.selectFrom(T2).fetchOne();
  46. System.out.println(row2);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement