Querulous -- Is it usable with a database other than MySQL?
I'm studying querulous and started with this code:
import com.twitter.querulous.evaluator.QueryEvaluator
class Querulous {
def test {
val queryEvaluator = QueryEvaluator("org.h2.Driver", "jdbc:h2:tcp://localhost/~/test", "sa", "")
val names = queryEvaluator.select("select (name) from mytable where id in (?)", List(1, 2, 3)) {
row =>
row.getString("name")
}
println(names)
}
}
The result of execution is following:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:343) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at org.apache.commons.dbcp.Driver开发者_Go百科ManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) at com.twitter.querulous.database.ApachePoolingDatabase.open(ApachePoolingDatabase.scala:93) at com.twitter.querulous.database.Database$class.withConnection(Database.scala:33) at com.twitter.querulous.database.ApachePoolingDatabase.withConnection(ApachePoolingDatabase.scala:45) at com.twitter.querulous.evaluator.StandardQueryEvaluator.withTransaction(StandardQueryEvaluator.scala:66) at com.twitter.querulous.evaluator.StandardQueryEvaluator.select(StandardQueryEvaluator.scala:23) at com.twitter.querulous.evaluator.QueryEvaluator$class.select(QueryEvaluator.scala:88) at com.twitter.querulous.evaluator.StandardQueryEvaluator.select(StandardQueryEvaluator.scala:19) at org.database.Querulous.test(Querulous.scala:10) at org.database.Main$.main(Main.scala:4) at org.database.Main.main(Main.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at sbt.Run.run0(Run.scala:60) at sbt.Run.execute$1(Run.scala:47) at sbt.Run$$anonfun$run$2.apply(Run.scala:50) at sbt.Run$$anonfun$run$2.apply(Run.scala:50) at sbt.TrapExit$.executeMain$1(TrapExit.scala:33) at sbt.TrapExit$$anon$1.run(TrapExit.scala:42) Caused by: java.net.UnknownHostException: org.h2.Driver at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:850) at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1201) at java.net.InetAddress.getAllByName0(InetAddress.java:1154) at java.net.InetAddress.getAllByName(InetAddress.java:1084) at java.net.InetAddress.getAllByName(InetAddress.java:1020) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:275) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:292) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:774) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75) at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1148) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) at com.twitter.querulous.database.ApachePoolingDatabase.open(ApachePoolingDatabase.scala:93) at com.twitter.querulous.database.Database$class.withConnection(Database.scala:33) at com.twitter.querulous.database.ApachePoolingDatabase.withConnection(ApachePoolingDatabase.scala:45) at com.twitter.querulous.evaluator.StandardQueryEvaluator.withTransaction(StandardQueryEvaluator.scala:66) at com.twitter.querulous.evaluator.StandardQueryEvaluator.select(StandardQueryEvaluator.scala:23) at com.twitter.querulous.evaluator.QueryEvaluator$class.select(QueryEvaluator.scala:88) at com.twitter.querulous.evaluator.StandardQueryEvaluator.select(StandardQueryEvaluator.scala:19) at org.database.Querulous.test(Querulous.scala:10) at org.database.Main$.main(Main.scala:4) at org.database.Main.main(Main.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at sbt.Run.run0(Run.scala:60) at sbt.Run.execute$1(Run.scala:47) at sbt.Run$$anonfun$run$2.apply(Run.scala:50) at sbt.Run$$anonfun$run$2.apply(Run.scala:50) at sbt.TrapExit$.executeMain$1(TrapExit.scala:33) at sbt.TrapExit$$anon$1.run(TrapExit.scala:42) [info] == run == [error] Error running run: Nonzero exit code: 1
As for me, it doesn't look very nice. It seems that querulous can be used only with mysql rdbms. Is that true? Secondly, there are a bunch of querulous projects1 2 3 4 with slightly different instructions, for examle, from 1:
val queryEvaluator = QueryEvaluator("host", "username", "password")
(I didn't figure out what "host" means)
from 2:
val queryEvaluator = QueryEvaluator("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/mydb", "username", "password")
(used this as sample)
And at last, I used "com.twitter" % "querulous_2.8.0" % "1.5.0" for binaries and cloned git://github.com/twitter/querulous.git to have sources (no 1.5 sources available for download) but they doesn't have any comments.
So, questions: can querulous be used with databases other than mysql? If so, please specify example how connect to it; scaladoc location; normal (with comments) sources location.
This fork claims to be more of a vanilla version of Querulous:
https://github.com/ollekullberg/querulous-light
From their readme:
Note about this Fork
This is a fork of Querulous-generic (Querulous-generic is in turn a fork of the Twitter version). This fork will:
- Work on Scala 2.8
- Work on all RDBMs (Well, I've only tried H2, so I do not really know)
- Not have any dependencies to Twitters StandardProject module.
The more advanced features (timeout and so on) probably don't work, since I had to smash some code to get here.
While I use querulous, I've only used it with mysql and have not tried this fork myself.
精彩评论