简体   繁体   English

将android应用连接到本地MS SQL数据库

[英]Connecting android app to local MS SQL database

I'm trying to connect my Android app to my local machine database MS SQL. 我正在尝试将我的Android应用程序连接到本地计算机数据库MS SQL。 This is my connection string: 这是我的连接字符串:

jdbc:jtds:sqlserver://localhost:1433/DajSve;encrypt=false;user=root;password=null;instance=FALE//SQLEXPRESS;

And I got this error: 我得到了这个错误:

java.sql.SQLException: Network error IOException: failed to connect to localhost/127.0.0.1 (port 1433): connect failed: ECCONREFUSED (Connection refused) java.sql.SQLException:网络错误IOException:无法连接到localhost / 127.0.0.1(端口1433):连接失败:ECCONREFUSED(连接被拒绝)

I tried a lot of things. 我尝试了很多事情。 Changed a connection string a lot of times, enabled TCP/IP and set it to port 1433, also turned off firewall but nothing helped. 多次更改连接字符串,启用TCP / IP并将其设置为端口1433,还关闭了防火墙,但无济于事。 I'm always getting the same SQL Exception. 我总是得到相同的SQL异常。 I'm using SQL Server 2016.. 我正在使用SQL Server 2016 ..

  try {

        Class.forName(className).newInstance();
        connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/DajSve;encrypt=false;user=root;password=null;instance=FALE//SQLEXPRESS;");

        System.out.print("Uspjesno spojeni na bazu");
        Statement stmt = connection.createStatement();
        ResultSet reset = stmt.executeQuery("select * from Korisnik");

        if (!reset.isBeforeFirst() ) {
            System.out.println("nema podataka");
        }else{
            System.out.println("ima podataka");
        }

    } catch (SQLException e) {
        e.printStackTrace();
        System.out.print("Greska pri spajanju na bazu");
    } catch (ClassNotFoundException e){
        System.out.print("Greska - klasa nije pronađena");
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

I know there is a lot of similar questions but none of the answers have helped 我知道有很多类似的问题,但没有一个答案有帮助

failed to connect to localhost/127.0.0.1 无法连接到localhost / 127.0.0.1

Your Android device isn't running a SQL Server. 您的Android设备未运行SQL Server。 Give the actual server address on your network 提供您网络上的实际服务器地址

It's not a local database when your code exists on a remote device 当您的代码存在于远程设备上时,它不是本地数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM