[英]How do I execute a count command using scala.dbc?
I am trying to connect to an MS/SQL server and execute a 'count' statement. 我正在尝试连接到MS / SQL服务器并执行“ count”语句。 I've reached this far: 我已经达到了这一点:
import scala.dbc._
import scala.dbc.Syntax._
import scala.dbc.syntax.Statement._
import java.net.URI
object MsSqlVendor extends Vendor {
val uri = new URI("jdbc:sqlserver://173.248.X.X:Y/DataBaseName")
val user = "XXX"
val pass = "XXX"
val retainedConnections = 5
val nativeDriverClass = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
val urlProtocolString = "jdbc:sqlserver:"
}
object Main {
def main(args: Array[String]) {
println("Hello, world!")
val db = new Database(MsSqlVendor)
val count = db.executeStatement {
select (count) from (technical)
}
println("%d rows counted", count)
}
}
I get an error saying: "scala.dbc.syntax.Statement.select of type dbc.syntax.Statement.SelectZygote does not take parameters" 我收到一条错误消息:“类型为dbc.syntax.Statement.SelectZygote的scala.dbc.syntax.Statement.select不带参数”
How do I set this up? 我该如何设置?
This can be a problem: 这可能是一个问题:
val count = db.executeStatement {
select (count) from (technical)
}
The count
inside the statement refers to val count
, not to some other count
. 语句中的count
是指val count
,而不是其他count
。 Still, there's the other problem you report. 尽管如此,您还报告了另一个问题。 There's neither a count
nor a technical
definition anywhere. 哪里都没有count
或technical
定义。 Maybe it is missing from some other place where you found this snippet. 也许在您找到此代码段的其他地方缺少它。 The following does compile, though it's anyone's guess as to whether it does what you want: 确实可以编译以下内容,尽管有人猜测它是否满足您的要求:
val countx = db.executeStatement {
select fields "count" from "technical"
}
At any rate, I thought scala.dbc was long deprecated. 无论如何,我认为scala.dbc早已被弃用。 I can't find any deprecation notice, however, and it is still linked on the library jar, even on trunk. 但是,我找不到任何不赞成使用的通知,并且它仍链接在库jar上,即使在主干上也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.