Displaying of data from your MySQL Database to your Java application is very important especially when you are working with update and delete functions.
In updating an deleting data, you need to specify and identify the unique keys/data before the delete and update function execute. By doing that, you need to display the data into the jTable so that you can select which row data you need to update or delete.
Required Libraries:
To create the this features in your application, your need to create a new method that holds the source codes below. After that, use a method calling by copying the method name and insert it into your public class.
![]() |
Image: Kenminds.in |
In updating an deleting data, you need to specify and identify the unique keys/data before the delete and update function execute. By doing that, you need to display the data into the jTable so that you can select which row data you need to update or delete.
Required Libraries:
- rs2xml.jar
To create the this features in your application, your need to create a new method that holds the source codes below. After that, use a method calling by copying the method name and insert it into your public class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{ | |
//query and execution | |
String sql="SELECT idCustomer as 'ID',RegNumber as '#',Name AS 'NAME',Address AS 'ADDRESS',Contact AS 'CONTACT' FROM customer"; | |
pst=conn.prepareStatement(sql); | |
rs = pst.executeQuery(sql); | |
jTable1.setModel(DbUtils.resultSetToTableModel(rs)); | |
//resize table column | |
TableColumnModel tcm = jTable1.getColumnModel(); | |
tcm.getColumn(0).setPreferredWidth(10); | |
tcm.getColumn(2).setPreferredWidth(200); | |
}catch(SQLException e) { | |
JOptionPane.showMessageDialog(this, e.getMessage()); | |
} |
0 Comments