1
我正嘗試使用Jasper報告生成一些報告給我的系統。我起訴基本JDBC連接方法來建立我的SQL Server 2000中的連接下面是我的代碼片段:JDBC | SQL Server連接錯誤
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)
謝謝。
什麼是connectString? – Dave 2011-06-13 09:31:25
我認爲您的摘錄之上的那一行會很有趣,因爲它是指示實際發生的異常的地方。 – 2011-06-13 09:37:01