0
beauty? I have a problem with a login of a system that I am creating, in which according to the type of user of the client, it will open the next form with some visible components or not. When I give a Sout to the variable in the login form (which receives the "type" field of the database) it appears, now if I do the same already in the menu form, ends up giving "null" in the terminal ie, the variable is not transiting. Detail is that when I first wrote the code worked, what happens here??? Note: I am a computer technician, I have basic/intermediate knowledge about Java, I wanted your opinion and what would you do to solve. Thanks in advance!
Login form code(I called the try method on the login button and the Keyevent event):
private final Connection connection;
public static String tipo;
public void tentativa() {
String login = txt_usuario.getText().trim();
try {
String sql = "SELECT tipo FROM usuario WHERE login = '" + login + "'";
PreparedStatement stmt = connection.prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
tipo = rs.getString("tipo");
System.out.println(tipo);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Menu form code:
public String tipo = "";
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
/**
* Creates new form form_menu
*/
public form_menu() {
initComponents();
this.setTipo(form_login.tipo);
System.out.println(tipo);
}
In the past, most java programs used JDBC but JPA came to make it easier because it doesn’t use JPA? when it comes to your code it is incomplete. see this: https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions? cb=1
– André Martins
After the login is done, there
form_menu()
if you do thisSystem.out.println(Connection.tipo)
what the result?– Augusto Vasques