Skip to content
Advertisement

Getting the data from SQL and inserting it inside the Java Textfield

I’ve been trying to get the data from the SQL and insert it inside the JTextfield.

Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:mysql://localhost:3306/Management", "root", "admin"); 
Statement st = connection.createStatement();
String sql ="SELECT * FROM information WHERE id =?";

pst=connection.prepareStatement(sql);
pst.setString(1,txtCustomerId.getText());
rs=pst.executeQuery();

if (rs.next()){
String ID = rs.getString("Firstname");
txtFirstname.setText(ID);
}

This code is in the button action, but when I clicked the button, there is nothing happening.

Advertisement

Answer

I redo my JFrame and rewrite this code. There is no problem with this code. I think it just override because I copied the previous JFrame.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement