Problema com laço de repetição

1 resposta
M

Estou tentando montar um KeyGen online…com banco de dados para evitar loop…o problema que ele sempre entra no laço de comparação mesmo quando é diferente…a primeira passada vai certinho mas da segunda em diante não deveria entrar no IF…alguém sabe o que esta rolando?

try
	{

		Class.forName("org.postgresql.Driver");
		Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/dota2key" ,"postgres" , "admin" );
		Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
		
		int A=1;
		int B=1;
		String s = null; //String a ser impressa  
		String K="ZW92E-BBKQI-3MYCR-KZ2D4-M2E3J"; 
        StringBuffer sb = new StringBuffer(); //StringBuffer para o append   
        int qtdChars = 1; //Qtd de chars na String   
        int qtdKey =1;
		
		ResultSet rs = st.executeQuery("select * from key order by key_codigo");
		while (rs.next())
		{
			out.println("entrou no laço 1<p>");
			rs.getString("key");
			out.println(rs.getString("key")+" || "+K);
			
			if (rs.getString("key")==(K));
				{
					out.println("entrou no laço 2");
					K="ZW92E-";
					while (qtdKey <= 3)
	 				{
		 			 s=null;
		 			 sb=new StringBuffer();
		 			 qtdChars=1;
        			 while(qtdChars <=5 ) //String tem que ter 16 chars  
				 		 {
           				 int charInt = (int) (Math.random() * 71);           
           				 if(((charInt >= 48) && (charInt <= 57)) || ((charInt >= 65) && (charInt <= 70)))
							{   
           	              	  	char c = (char) charInt;
              	 				sb.append(c);
                   	   			qtdChars++;    
            				}   
						B++;      
        				} 
				s = sb.toString()+"-";
				K=K+s;
				qtdKey++;
	 				}
		  		s=null;
		  		sb=new StringBuffer();
		  		qtdChars=1;
          		while(qtdChars <=5 ) //String tem que ter 16 chars  
				 	 {
						 //out.println("entrando no ultimo laço");
           				 int charInt = (int) (Math.random() * 71);           
           				 if(((charInt >= 48) && (charInt <= 57)) || ((charInt >= 65) && (charInt <= 70)))
							{   
           	              	  	char c = (char) charInt;
              	 				sb.append(c);
                   	   			qtdChars++;    
            				}   
						B++;      
        			} 
				s = sb.toString();
				K=K+s;
				}
			if (rs.getString("key")!=(K));
				out.println("entrou no 3<p><p>");
				K=K;
		}
%></p>
<p>&nbsp;</p>

1 Resposta

Thishinoda

Sempre use o método equals da classe String para comparar valores String.

Criado 14 de fevereiro de 2012
Ultima resposta 23 de fev. de 2012
Respostas 1
Participantes 2