我遇到了这个问题,这应该不是问题
我写了这段代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
/**
* @author ZEESHAN
*/
public class TestApps
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Connection con;
// Statement stmt;
ResultSet rs;
String str,str2,str3;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:TestApp");
Statement stmt = con.createStatement();
System.out.println("Connected");
rs=stmt.executeQuery("SELECT Emp_Name,Emp_LastName FROM Table_1 WHERE Emp_Name = 'zeeshan' ");
while(rs.next())
{
str = rs.getString("Emp_Name");
str2 = rs.getString("Emp_LastName");
String name,pass;
Scanner input = new Scanner(System.in);
name = input.nextLine();
pass = input.nextLine();
if(name.equals(str) && pass.equals(str2) )
{
System.out.println("CORRECT");
}
else
{
System.out.println("INCORRECT");
System.out.println(""+name);
System.out.println(""+pass);
System.out.println(""+str);
System.out.println(""+str2);
}
}
// String name,pass;
/*
if(name.equals(str) && pass.equals(str2) )
{
System.out.println("Correct");
}
else
{
System.out.println("Incorrect");
}
*/
}
catch (Exception ex)
{
System.out.println("Not connected");
ex.printStackTrace();
}
}
}
一切正常,即数据库和所有。我给出了与数据库字符串相同的答案,但我得到的结果并不好,而且结果表明所有字符串都是相同的答案,但是为什么我仍然没有达到真实的条件我得到了错误的条件在控制台中回答。
RESULT:
INCORRECT
zeeshan
ismail
zeeshan
ismail