我写了一些代码,它应该从我的SQL服务器中提取信息,以告知当前正在运行的项目。 代码在我的Windows机器上运行正常,但我打算在运行Raspbian Jessie的覆盆子pi上运行它。当我运行代码时,它给了我错误
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host H79SQLMERINSQL, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
当我在我的Windows机器上运行我的代码时,它运行完全正常,并给我项目编号
以下是代码:
public void main(String []args) {
// address of the SQL Server
String connectionUrl = "jdbc:sqlserver://H79SQLMERINSQL:1433;" +
"databaseName=runtime;user=sa;password=sa;";
//ErrorDialog errors = new ErrorDialog();
// Declaration of variables
//JDBC objects
Connection conURL = null;
Statement statement = null;
ResultSet receivedStatement = null;
//Variables for calling
String itemNumber = null;
//The following code is where all of the SQL Server connections happen and the setting of variables for use later
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conURL = DriverManager.getConnection(connectionUrl);
System.out.println("Not Prblem");
// Create and execute an SQL statement that returns some data.
statement = conURL.createStatement();
receivedStatement = statement.executeQuery("SELECT Value "
+ "FROM v_StringLive "
+ "WHERE v_StringLive.TagName IN ('MD_ProcessData.ItemNumberMD1')");
// Iterate through the data in the result set and display it.
while (receivedStatement.next()) {
itemNumber = receivedStatement.getString(1);
//Below code is for displaying to the system
/*System.out.println("The item number is: "+receivedStatement.getString(2) + " " + receivedStatement.getString(6));*/
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
System.out.println("Error 101: Connection to SQL Server has timed out");
e.printStackTrace();
}
finally {
if (receivedStatement != null) try { receivedStatement.close(); } catch(Exception e) {}
if (statement != null) try { statement.close(); } catch(Exception e) {}
if (conURL != null) try { conURL.close(); } catch(Exception e) {}
}
System.out.println("Item: " + itemNumber);
}
我确保在我的SQL Server配置管理器中,我的IP地址全部设置为TCP端口1433,并且TCP动态端口设置为空白。
我花了很多时间试图弄清楚这一点没有成功,非常感谢任何帮助。 谢谢大家