繁体   English   中英

JDBC | SQL 服务器连接错误

[英]JDBC | SQL Server connection error

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

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)

谢谢。

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

 Line 2: Incorrect syntax near '|'.

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

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

还要确保您的 jars 位于正确的位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM