Estou tentando conectar nosso DB via Java no Ubuntu. Eu estou usando VPN para conectar-se ao servidor. VPN é conectado com sucesso, mas quando eu estava executando o programa, tenho enfrentado essa mensagem de erro:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.35, port 1433 has failed. Error: "connect timed out. 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.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at Main.main(Main.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)**
Eu tentei esta postagem, mas não trabalhei: Conexão MSSQL do Ubuntu Como conectar um banco de dados MSSQL do Ubuntu 14.04?
Aqui está o meu código java:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Statement stmt = null;
String query = "select * " +
"from DBName.dbo.tblCity" ;
System.out.println(query);
try {
String URL = "jdbc:sqlserver://192.168.1.35:1433;databaseName=DBName;integratedSecurity=false";
String USER = "USER";
String PASS = "PASS.";
Properties connectionProperties = new Properties();
connectionProperties.put("username", USER);
connectionProperties.put("password", PASS);
Connection conn = DriverManager.getConnection(URL, connectionProperties);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String strHomePageUrl=rs.getString("strCity");
int intCityID=rs.getInt("intCityID");
System.out.println(strHomePageUrl + " " + intCityID);
System.out.println(strHomePageUrl + "\t" + intCityID );
}
} catch (SQLException e ) {
System.out.println("Bağlantı kurulamadı");
e.printStackTrace();
} finally {
if (stmt != null) {
System.out.println("İşlem Başarılı");
}
}
}
}
Ele também trabalhou no Windows.
Tem alguma ideia para resolver este problema?