Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何测试SQL server连接?_Java_Sql Server_Android Studio_Jdbc_Azure Sql Database - Fatal编程技术网

Java 如何测试SQL server连接?

Java 如何测试SQL server连接?,java,sql-server,android-studio,jdbc,azure-sql-database,Java,Sql Server,Android Studio,Jdbc,Azure Sql Database,我有以下登录页面的代码 我创建了以下内容以获取在接收凭据的框中输入的数据 final String NameHere = HeldUser.getText().toString(); final String PasswordHere = HeldPasssword.getText().toString(); 下面是我的查询,将它们与数据库中的内容进行比较 ArryList<String> names= null; ArrayList<String> passw

我有以下登录页面的代码

我创建了以下内容以获取在接收凭据的框中输入的数据

final String NameHere = HeldUser.getText().toString();
    final String PasswordHere = HeldPasssword.getText().toString();
下面是我的查询,将它们与数据库中的内容进行比较

ArryList<String> names= null;
ArrayList<String> password = null;
try{ 
con = MyConnectionClass(); 
String query = null;
if(con == null){
z = "Check Your Internet Access!"; 
                 // I have a toast RIGHT HERE to that I figured would trigger
                    the connection was not successful.. 
                Toast.makeText(Async.this, "Connection failures. Contact Administrator.", Toast.LENGTH_SHORT).show();

} else { 
if (Condition that I know is being triggered){
MyQueryDeclaredEarlier = "select * from MyTable where Username = '"+NameHere+ "'and Password = '"+PasswordHere+"'";
//     The above was written with the +NameHere+ and +PasswordHere+ variables 
         receive String from EditTextBoxes I have for gathering credentials 

//     The Columns (Username and Password) are correct and the tablename (Table) 
       is also, as is, in the SQL management database. (I exluded dbo.) 

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(MyQueryDeclaredEarlier); 

while (rs.next()){
names.add(0,rs.getString("Username"));
password.add(0,rs.getString("Password"));
}
// then I just compare the username variable (NameHere) contents to 
// the string I got from the ResultSet (rs) and added to the ListArray (names)
at position 0. 
// I think this where the problem is. 
String FromQuery = names.get(0).toString();
if(NameHere.equals(FromQuery)){
z = "query successful"
isSuccess = true;
}
else{ 
z = "Invalid Query!"; 
isSuccess = false; 
} 
ArryList name=null;
ArrayList密码=null;
试试{
con=MyConnectionClass();
字符串查询=null;
如果(con==null){
z=“检查您的互联网接入!”;
//我在这里为我认为会触发的事件干杯
连接不成功。。
Toast.makeText(Async.this,“连接失败。请与管理员联系。”,Toast.LENGTH_SHORT.show();
}否则{
如果(我知道的条件正在被触发){
MyQueryDeclareDearier=“从MyTable中选择*,其中用户名='“+NameHere+”,密码='“+PasswordHere+”;
//上面是用+NameHere+和+PasswordHere+变量编写的
从我用于收集凭据的EditTextBox接收字符串
//列(用户名和密码)正确,表名(表)
同样,也在SQL管理数据库中(我排除了dbo)
语句stmt=con.createStatement();
结果集rs=stmt.executeQuery(MyQueryClaredier);
while(rs.next()){
name.add(0,rs.getString(“用户名”);
添加(0,rs.getString(“密码”);
}
//然后我将username变量(NameHere)的内容与
//从ResultSet(rs)中获取并添加到ListArray(名称)的字符串
在第0位。
//我认为这就是问题所在。
String FromQuery=names.get(0.toString();
if(NameHere.equals(FromQuery)){
z=“查询成功”
isSuccess=true;
}
否则{
z=“无效查询!”;
isSuccess=false;
} 
伊玛把剩下的都忘了

它一直将isSuccess返回为false

他们有没有简单的方法来测试实际的连接?
我已经将两个模块附加到这个项目中。包括了相应的依赖项,但我不确定它们是否没有其他我看不到的内容,或者Android无法为我阅读的内容。帮助。

修复。我创建了一个列表数组,并在开始时完成了它。而不是玩布尔值(这是实际的问题),我在从DoinBAckground方法传递的字符串的postExecute中进行了验证。仍然无法确认从文本框中获取字符的字符串变量与从查询中收集的字符串是否匹配,因为我在mysql-connector-java-3.0.17-ga-bin.java驱动程序中遇到了问题。作为一个模块Had,但似乎不是o正在工作。将其放入库中,并将依赖项设置为编译文件:libs/drivername,而不是使用编译项目:drivername


不确定这是否有效,但我需要尽快进行测试。如果我需要更多帮助,我会提出一个新问题,但我认为我可以单独完成这部分。

很明显,
NameHere.equals(FromQuery)
的计算结果不是真的。为什么不调试它以查看您返回的值?或者,是否可以进行任何日志记录?我实际上想出了一些不同的方法。不过,感谢您的建议!从现在起,我正在努力使sql驱动程序集成。可能即将发布一个新问题。点击它一点,看看是什么在此之前,我可以得到。谢谢!请不要回答你的问题与“固定!!!!”。相反,制定一个好的答案,解释你解决这个问题的步骤,这样未来的读者可能会学到一些东西/得到他们想要的帮助。=)我只是不想用未解决的问题把网站弄得一团糟。如果我只是想简单地把问题解决,我想发垃圾邮件并不是恶意的。。