-1
I am using the JDBC driver to connect my program to the database and when I use the getString method it makes me a string that I can print on screen but when comparing this string that it returns to me with another string of same value the result is false, I made a code to demonstrate this: test package;
import java.sql.Connection; import java.sql.Drivermanager; import java.sql.Resultset; import java.sql.Sqlexception; import java.sql.Statement;
public class Testescomdb { public Static void main(String[] args) { Connection connected; String url ="jdbc:mariadb://localhost:3306:/javateste"; String user = "root"; String password = ""; Try { connection = Drivermanager.getConnection(url,user,password); Statement stmt = connection.createStatement(); String command = "INSERT INTO tabProduct (codigoProduct,descProduct) VALUES(1,'ball') "; stmt.executeUpdate(command); Resultset rs = stmt.executeQuery("SELECT * FROM tabProduct"); while(rs.next()) { int c = rs.getInt("codigoProduct"); String d = rs.getString("descProduct");
System.out.println(d=="bola");
System.out.println(c+" "+d);
}
}
catch(SQLException exe){
System.out.println("\nMais q porra deu um erro no sql: "+exe);
}
catch(Exception exe) {
System.out.println("\nMais q porra deu um erro:"+exe);
}
}
} Obs: the table used from is obtained from the : create table tabProduct (codigoProduto integer, descProduto char(30));
This answers your question? How to compare Strings in Java?
– hkotsubo