You are on page 1of 2

//Simple query using GUI

private void } catch (Exception e1)


jButton1ActionPerformed(java.awt.event.ActionEv
ent evt) { {

// TODO add your handling code here JOptionPane.showMessageDialog(this,


DefaultTableModel model=new "Connection Problem");
DefaultTableModel(new
return;//Update student set
String[]{"ROLLNO","NAME","MARKS"},0);
name='abhishek' where roll_no=1
try (Connection con = getconnection();
}}
Statement st = con.createStatement())

{String str = jt.getText();

ResultSet rs = st.executeQuery(str);

while (rs.next()) {

int roll=rs.getInt(1);

String name=rs.getString(2);

int mks=rs.getInt(3);

model.addRow(new Object[]{roll,name,mks});} }

jtable1.setModel(model);

} catch (Exception e1)

{ JOptionPane.showMessageDialog(this,
"Connection Problem");

e1.printStackTrace();

return;} }

private void
btnActionPerformed(java.awt.event.ActionEvent
evt) {

// TODO add your handling code here:

try (Connection con = getconnection();

Statement st = con.createStatement())

String str = jt.getText();

st.executeUpdate(str);

You might also like