private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/inventry","root","");
Statement stemt=con.createStatement();
String str = "select * from addproducts";
ResultSet rs = stemt.executeQuery(str);
while(rs.next())
{
model.addRow(new Object[]{rs.getString("pslno"),rs.getString("pid"),rs.getString("pname"),rs.getString("pcategory"),rs.getString("pqty"),rs.getString("ppurcst"),rs.getString("psalprc"),rs.getString("pcmprc"),rs.getString("pdate"),});
}
}catch(Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
It is working and display all database table records on JTable
but,
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/inventry","root","");
Statement stemt=con.createStatement();
String StrQr="";
if (prid.getText().trim().length()>0 ) {
StrQr=StrQr + " and pid = " + prid.getText().trim() + " ";
String str = "select pid, pname,pslno,pcategory,pqty,ppurcst,psalprc,pcmprc from addproducts where 1=1 " + StrQr + " order by pid";
ResultSet rs = stemt.executeQuery(str);
JOptionPane.showMessageDialog(null,"connected");
while(rs.next()) {
model.addRow(new Object[]{rs.getString("pslno"),rs.getString("pid"),rs.getString("pname"),rs.getString("pcategory"),rs.getString("pqty"),rs.getString("ppurcst"),rs.getString("psalprc"),rs.getString("pcmprc"),rs.getString("pdate"),});
}
}
} catch (Exception e) {
System.err.println(e);
//System.exit(1);
}
}
I want to display particular p_id row on JTable
but it is not working. No errors occurred.