我正在为我的移动软件工程课程开发一个Android应用程序用于研究生学校,我有点陷入困境。我在建立连接时遇到了麻烦。有人可以帮助我吗?我在somee.com上有一个免费的云数据库,我使用的是SQL Server数据库。以下是信息:
MS SQL Server地址:
Testdev.mssql.somee.com
登录名:
vahharris_SQLLogin_1
登录密码:
bjl58ms4iy
连接字符串: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
这是我目前的代码
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());
}
}
}
答案 0 :(得分:0)
您的用户名似乎在其定义中有一个尾随空格:
String username = "vahharris_SQLLogin_1 ";
您尚未发布您所看到的错误,但如果登录失败,则可能是原因。