Advertisement
Guest User

Untitled

a guest
May 17th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. scala> Class.forName("org.postgresql.Driver")
  2. res0: Class[_] = class org.postgresql.Driver
  3.  
  4. scala> val props = new java.util.Properties
  5. props: java.util.Properties = {}
  6.  
  7. scala> props.setProperty("user","vagrant")
  8. res1: Object = null
  9.  
  10. scala> props.setProperty("password","vagrant")
  11. res2: Object = null
  12.  
  13. scala> props.setProperty("statement_timeout", "1")
  14. res4: Object = null
  15.  
  16. scala> props
  17. res5: java.util.Properties = {statement_timeout=1, user=vagrant, password=vagrant}
  18.  
  19. scala> java.sql.DriverManager.getConnection("jdbc:postgresql://localhost/vagrant", props)
  20. res6: java.sql.Connection = org.postgresql.jdbc4.Jdbc4Connection@32eb8dc1
  21.  
  22. scala> implicit val c: java.sql.Connection = res6
  23. c: java.sql.Connection = org.postgresql.jdbc4.Jdbc4Connection@32eb8dc1
  24.  
  25. scala> anorm.SQL("select count(*) from foo")().toList
  26. res8: List[anorm.Row] = List(Row(ColumnName(.count,Some(count)): 8749099 as java.lang.Long))
  27.  
  28. scala> anorm.SQL("set statement_timeout = 1").execute()
  29. res11: Boolean = false
  30.  
  31. scala> anorm.SQL("select count(*) from foo")().toList
  32. org.postgresql.util.PSQLException: ERROR: canceling statement due to statement timeout
  33. at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
  34. at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
  35. at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
  36. at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
  37. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
  38. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:305)
  39. at anorm.Sql$class.resultSet(Anorm.scala:286)
  40. at anorm.SqlQuery.resultSet(Anorm.scala:384)
  41. at anorm.Sql$class.apply(Anorm.scala:281)
  42. at anorm.SqlQuery.apply(Anorm.scala:384)
  43. ... 43 elided
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement