简体   繁体   English

如何使用scala.dbc执行count命令?

[英]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. 哪里都没有counttechnical定义。 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.

相关问题 我如何不使用count(*)来检查是否存在某些东西…限制1 - How do i check if something exist without using count(*) … limit 1 如何使用联接获取成员数 - how do i get the member count using joins VB6 + SQL-Server:如何使用ADODB.Command执行带有命名参数的查询? - VB6+SQL-Server: How can I execute a Query with named parameters using ADODB.Command? 如何在 C# 中使用 ADO.NET 执行 SQL 命令? - How to execute SQL command using ADO.NET in C#? 使用 Scala 在 Databricks 中执行一系列存储过程 - Execute series of Stored procedures in Databricks using Scala 如何对 SQLServer 数据库执行 SELECT 查询并使用 PowerShell 迭代结果 - How do I execute a SELECT query against a SQLServer database and iterate results using PowerShell 如何在构建时使用数据库项目执行主数据SQL脚本 - How do I execute master data sql script using database project on build 如何使用 TSQL 确定哪些角色被授予对特定存储过程的执行权限? - How do I determine using TSQL what roles are granted execute permissions on a specific stored procedure? 如何在SQL中按天计算出现次数? - How do I count occurrences by day in SQL? 我如何获得最大计数的详细信息? - How do i get the details of the max of a count?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM