Vous êtes sur la page 1sur 2

VIEW

DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
String query="select * from comp_stock";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=(Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/dpsg","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
String a=rs.getString("itmcode");
String b=rs.getString("itmname");
String c=rs.getString("qtyissued");
model.addRow(new Object []{a,b,c});
}
}
catch(Exception d)
{
JOptionPane.showMessageDialog(null,d.getMessage());
}
INSERT
String sq="select * from comp_stock";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql:/
/localhost:3306/dpsg","root","");
Statement stmt=con.createStatement();
ResultSet rs=null;
String a=jTextField1.getText();
String b=jTextField2.getText();
String c=jTextField3.getText();
int r= stmt.executeUpdate("insert into comp_stock(itmcode," +
"itmname,qtyissued) values(" +
"'"+jTextField1.getText()+"','"+jTextField2.getText()+"','"+
jTextField3.getText() +"');");
JOptionPane.showMessageDialog(null, "Ok");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
UPDATE
String sq="select * from comp_stock";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql:/
/localhost:3306/dpsg","root","");
Statement stmt=con.createStatement();
ResultSet rs=null;
String a=jTextField4.getText();
stmt.executeUpdate("update comp_stock set itmname='"+(jTextField2.ge
tText())+"' , qtyissued='"+(jTextField3.getText())+"' , itmcode='"+(jTextField1.
getText())+"' where itmcode='"+(jTextField4.getText())+"'");
JOptionPane.showMessageDialog(null, "Ok");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
DELETE
String sq="select * from comp_stock";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql:/
/localhost:3306/dpsg","root","");
Statement stmt=con.createStatement();
ResultSet rs=null;
String a=jTextField4.getText();
stmt.executeUpdate("delete from comp_stock where itmcode='"+(a)+"'")
;
JOptionPane.showMessageDialog(null, "Ok");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}

Vous aimerez peut-être aussi