开发者

JDBC | SQL Server connection error

开发者 https://www.devze.com 2023-03-12 18:02 出处:网络
I\'m trying to generate some reports to my system using Jasper reports. I\'m suing basic JDBC connection method to establish a connection to my SQL Server 2000. Here is my code snippet:

I'm trying to generate some reports to my system using Jasper reports. I'm suing basic JDBC connection method to establish a connection to my SQL Server 2000. Here is my code snippet:

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

But I'm getting a SQL incorrect syntax exception.

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(Unk开发者_StackOverflow社区nown 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)

Thanks.


The first line of the exception you get says:

 Line 2: Incorrect syntax near '|'.

Check to see where you have the '|' in your source. In case of doubt try these:

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

Make also sure your jars are at the right place.

0

精彩评论

暂无评论...
验证码 换一张
取 消