Before doing this, you need to watch this video!
watch the designing part in the video section given below:
Connection code:
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
First create one function showTableData() and write the following code inside this function!
Call this function inside the constructor of the class! i.e. in the next line of initComponents();
now create the mouse clicked event of the jtable and write the following code!
You need to import two library file mysql connector and rs2xml jar file. The link of that file is provided in the video description section.
Watch the video:
watch the designing part in the video section given below:
Connection code:
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
First create one function showTableData() and write the following code inside this function!
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/combobox","root","");
String sql = "SELECT * FROM combobox";
pst = con.prepareStatement(sql);
rs=pst.executeQuery();
jTable2.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
Call this function inside the constructor of the class! i.e. in the next line of initComponents();
now create the mouse clicked event of the jtable and write the following code!
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/combobox","root","");
int row = jTable2.getSelectedRow();
String tblclick = (jTable2.getModel().getValueAt(row, 0).toString());
String sql = "select * from combobox where Rollno ="+tblclick+"";
pst = con.prepareStatement(sql);
rs=pst.executeQuery();
if(rs.next())
{
String Roll = String.valueOf(rs.getInt("Rollno"));
jTextField1.setText(Roll);
String firstname = rs.getString("fname");
jTextField2.setText(firstname);
String lastname = rs.getString("lname");
jTextField3.setText(lastname);
String add = rs.getString("address");
jTextField4.setText(add);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex);
}
You need to import two library file mysql connector and rs2xml jar file. The link of that file is provided in the video description section.
Watch the video:
No comments:
Post a Comment