0
votes

I am working on an Android App for my Mobile Software Engineering class for grad school and I am a bit in a bind. I am having troubles establishing my connection. Can some one assist me with this? I have a database in the cloud that is free on somee.com that I use which is a SQL Server Database. Here is the information:

MS SQL Server address:

Testdev.mssql.somee.com

Login name:

 vahharris_SQLLogin_1

Login password:

 bjl58ms4iy

Connection string: workstation id=Testdev.mssql.somee.com;packet size=4096;user id=vahharris_SQLLogin_1;pwd=bjl58ms4iy;data source=Testdev.mssql.somee.com;persist security info=False;initial catalog=Testdev

Here is my current code

 package com.test.keeptraq;

 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.util.Log;
 import android.widget.EditText;
 import android.widget.TextView;

 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;


 public class Login extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_1);
    try{

        // Set the connection string
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        String username = "vahharris_SQLLogin_1 ";
        String password = "bjl58ms4iy";

        Connection DBconn = DriverManager.getConnection("jdbc:jtds:sqlserver://Testdev.mssql.somee.com/Testdev;user="+username+";password="+password);
        Log.w("Connection","open");

        Statement stmt = DBconn.createStatement();
        ResultSet resultSet = stmt.executeQuery("select * from Customer");

        TextView text = (TextView) findViewById(R.id.login_label);
        text.setText(resultSet.getString(1));

        DBconn.close();

    }catch(Exception e){

        Log.w("Error connection",""+ e.getMessage());


    }

}

}

1
What does “having troubles” mean? You're getting an error message? Post it. You're not getting the result you expected? Post what you expected and what you got.Dour High Arch
Please don't post your username and password online like this. Anybody can now connect to your database, which is obviously a security issue.Dan J
I am not getting the result. I am not receving an error at all. I am just not getting results. My results need to show in the textview and it's notJavar Harris
Dan J. Thanks. I put it up here cause it's a dummy DB I use. Never used for production purposes. So I'm alright. Appreciate your concern though.Javar Harris

1 Answers

0
votes

Your username seems to have a trailing space in its definition:

String username = "vahharris_SQLLogin_1 ";

You haven't posted what error you're seeing, but if it's a failure to login, that might be the cause.