Display Data from Selected Table Row to another Form in Java


This tutorial entitled “Display Data from Selected Table Row to another Form in Java” will help you on how your program display information from selected Table Row and display it to another form in Java using any element that support text.

To complete this tutorial, you are required to learn and understand my last topic about “How to Load Data from MySQL Database to Table Element in Java”. Please follow all the steps to complete this tutorial.

Display Data from Selected Table Row to another Form in Java Steps

  1. Add a new button inside your form that loads data from MySQL Database.

2. The form should look like the image below.

3. Double click the button and insert the ff. codes below.

[java]int row=jTable1.getSelectedRow();
String id = (jTable1.getModel().getValueAt(row, 0).toString());
DataUpdate du = new DataUpdate();

DataUpdate – the name of your form create in Step 4, loadInformation – the name of the method inserted in step 6, jTable1 – the name of your Table.

4. Add/Insert a new JFrame Form into your project.

5. Design your form just like what we do in our Save Data tutorial.

6. Inside your code view, insert the ff. codes below inside your class.

[java]public void loadInformation(String id){
String sql=”SELECT * FROM userinfo WHERE idUserInfo='” + id + “‘”;
rs = pst.executeQuery(sql);
catch(Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());

7. Run your load data form and the output should look like the image below. After I click the update button, the new Create form displayed together with the information selected from load data table.

Related Articles You May Like:

Looking for more source code? Type your keyword here here!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.