将我的Android应用程序连接到本地sql server时出错

时间:2015-08-23 23:34:09

标签: android sql-server jdbc android-studio

将我的Android应用程序连接到本地sql server(通过visual studio连接到同一台PC)时出现错误

  

27506-27506 / com.example.jacquesarroyo.onlinelibrary E / ERROR:网络   错误IOException:无法连接到/10.0.0.5(端口1433):connect   失败:ETIMEDOUT(连接超时)

这是我的代码:

add = (Button) findViewById(R.id.btnadd);
errorlbl = (TextView) findViewById(R.id.lblerror);
title = (EditText) findViewById(R.id.txttitle);
author = (EditText) findViewById(R.id.txtauthor);
year = (EditText) findViewById(R.id.txtyear);
location = (EditText) findViewById(R.id.txtlocation);

ipaddress = "10.0.0.5";   
db = "SampleDatabase"; 
username = "admin"
 password = "admin";
connect = ConnectionHelper(username, password, db, ipaddress);

    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                st = connect.createStatement();
                preparedStatement = connect
                        .prepareStatement("Insert into Books(Title,Author,Year) values ('"
                                + title.getText().toString()
                                + "','"
                                + author.getText().toString()
                                + "','"
                                + year.getText().toString() + "')");
                preparedStatement.executeUpdate();
                errorlbl.setText("Data Added successfully");
            } catch (SQLException e) {
                errorlbl.setText(e.getMessage().toString());
            }
        }
    });

我使用的IP地址是我的地址。

0 个答案:

没有答案