0

I am trying to connect our DB via Java in ubuntu. I am using VPN to connect out server. VPN is succesfully connected but when I was running program, I have been facing this error message:

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)**

I have tried this posts but i didn't work: MSSQL connection from Ubuntu How to connect a MSSQL database from Ubuntu 14.04?

Here is my java code:

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ı");
            }
    }
}

}

It has also worked on windows.

Do you have any idea for solve this problem?

3
  • I haven't done it yet..but did u install JDBC properly?
    – minigeek
    Oct 5, 2016 at 9:27
  • I tried but it didn't work Oct 6, 2016 at 5:25
  • Search for how to configure JDBC..i dont know about it much..may b someone can answer u
    – minigeek
    Oct 6, 2016 at 5:29

0

You must log in to answer this question.

Browse other questions tagged .