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());
}
}
}