【问题标题】:JDBC | SQL Server connection errorJDBC | SQL Server 连接错误
【发布时间】:2011-06-13 09:29:40
【问题描述】:

我正在尝试使用 Jasper 报告为我的系统生成一些报告。我正在使用基本的 JDBC 连接方法来建立与我的 SQL Server 2000 的连接。这是我的代码 sn-p:

public static Connection getConnection()throws ClassNotFoundException, SQLException 
{
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(connectString, user, password);
    return conn;
}

但是我得到一个 SQL 不正确的语法异常。

Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 2: Incorrect syntax near '|'.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
    at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
    at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
    at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:478)

谢谢。

【问题讨论】:

  • 我认为您的摘录正上方的那一行会很有趣,因为它是实际发生异常的地方。

标签: java sql sql-server jdbc jasper-reports


【解决方案1】:

你得到的异常的第一行说:

 Line 2: Incorrect syntax near '|'.

检查你在哪里有'|'在你的来源。如有疑问,请尝试以下方法:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433", user, password);

还要确保您的罐子放在正确的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 2013-04-13
    • 2017-10-17
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多