Вы находитесь на странице: 1из 2

Top:-

import java.sql.*;
import javax.swing.JOptionPane;

Public class:-
Connection X = null;
Statement y = null;
ResultSet z = null;

Add button:-
int a= Integer.parseInt(t1.getText());
String b=t2.getText();
String c=t3.getText();
int d= Integer.parseInt(t4.getText());
int e= Integer.parseInt(t5.getText());
try {
Class.forName("java.sql.Driver");
x = DriverManager.getConnection
("jdbc:mysql://localhost/try", "root", "yash");
y = x.createStatement();
String s = "select*from stu where Sr_no="+t1.getText()+";";
z= y.executeQuery(s);
if(z.next()){
JOptionPane.showMessageDialog(null, "Sr_no already exist"); }
else{
String Q = "Insert into stu values ("+a+",'"+b+"','"+c+"',"+d+","+e+");";
y.executeUpdate(Q);
JOptionPane.showMessageDialog(null, "Submited");}
} catch (Exception K) {
JOptionPane.showMessageDialog(null, "Error in Connectivity");
}
Load button:-
try {
Class.forName("java.sql.Driver");
x = DriverManager.getConnection
("jdbc:mysql://localhost/try", "root", "yash");
y = x.createStatement();
String Q = "select*from stu where Sr_no="+t1.getText()+";";
z= y.executeQuery(Q);
if(z.next()){
String a=z.getString( "Sr_no");
String b=z.getString( "Product_type");
String c=z.getString( "Product_Name");
String d=z.getString( "Price");
String e=z.getString( "Quantity");
t2.setText(b); t3.setText(c); t4.setText(d);
t5.setText(e);
bu.setEnabled(true);
bd.setEnabled(true);
t1.setEditable(false);
}else{ JOptionPane.showMessageDialog(null, "No such record
found"); }
} catch (Exception K) { JOptionPane.showMessageDialog(null, "Error in
Connectivity"); }
Update button:-
int a= Integer.parseInt(t1.getText());
String b=t2.getText();
String c=t3.getText();
int d= Integer.parseInt(t4.getText());
int e= Integer.parseInt(t5.getText());

int u= JOptionPane.showConfirmDialog
(null, "wanna update the record for sure?");
if(u==JOptionPane.YES_OPTION)
{ try {
y = x.createStatement();
String Q= "UPDATE stu SET
Sr_no="+a+",Product_type='"+b+"',Product_Name='"+c+"',Price="+d+",Quantity="+e+"
where Sr_no="+a+";";
y.executeUpdate(Q);
JOptionPane.showMessageDialog(null, "Record submited!");
}
catch (Exception K){
JOptionPane.showMessageDialog(null, "Error in Connectivity");
}
}
t1.setText(""); t2.setText(""); t3.setText(""); t4.setText("");
t5.setText("");
bu.setEnabled(false);
bd.setEnabled(false);
t1.setEditable(true);

Delete button:-
int o= JOptionPane.showConfirmDialog
(null, "wanna delete the record for sure?");
if(o==JOptionPane.YES_OPTION)
{
try {
y = x.createStatement();
String Q= "delete from stu where Sr_no="+t1.getText() +";";
y.executeUpdate(Q);
JOptionPane.showMessageDialog(null, "Record deleted!");
}
catch (Exception K){
JOptionPane.showMessageDialog(null, "Error in Connectivity");
}
}
t1.setText(""); t2.setText(""); t3.setText(""); t4.setText("");
t5.setText("");
bu.setEnabled(false);
bd.setEnabled(false);
t1.setEditable(true);

Вам также может понравиться