You are on page 1of 3

Step4: create individual frames for every table

package hospital;
import com.mysql.jdbc.Connection;
import java.awt.HeadlessException;
import java.sql.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

public class patient extends javax.swing.JFrame {


Connection connect = null;
ResultSet rst=null;
PreparedStatement pst=null;

public patient() {
initComponents();
connect = (Connection) Hospital.connDB();
}

@SuppressWarnings("unchecked")

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


try {

Statement s=connect.createStatement();
String sql = "insert into patient values('"+jTextField1.getText()+"','"+jTextField2.getText()+"','"+jTextField3.getText()
+"')";
s.executeUpdate(sql);

JOptionPane.showMessageDialog(null, "Success !");


jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
}
catch (HeadlessException | SQLException e) {
System.out.println("errorrr");
}
}

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

try
{
String sql="delete from patient where pid='"+jTextField2.getText()+"'";

Statement s=connect.createStatement();

s.executeUpdate(sql);

JOptionPane.showMessageDialog(null," Patient Records Deleted Succssfully... ");


jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField2.requestFocusInWindow();

catch(Exception ee)
{

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

try
{

String sql="update patient set name='"+jTextField1.getText()+"',disease='"+jTextField3.getText()+"' where


pid='"+jTextField2.getText()+"'";

Statement s=connect.createStatement();

s.executeUpdate(sql);

JOptionPane.showMessageDialog(null," Patient Records UPdated Succssfully... ");

jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");

jTextField2.requestFocusInWindow();

catch(Exception ee)
{
JOptionPane.showMessageDialog(null," Erro="+ee);

}
}

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


// TODO add your handling code here:

try
{
String sql="select * from patient where pid='"+jTextField2.getText()+"'";

Statement s=connect.createStatement();

rst=s.executeQuery(sql);
if(rst.next()==false)
{
JOptionPane.showMessageDialog(null," No Such Records Invalid Pid");

jTextField2.setText("");

jTextField2.requestFocusInWindow();
}
else
{
jTextField1.setText(rst.getString(1));
jTextField3.setText(rst.getString(3));

}
catch(Exception ee)
{

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

mainclass x1=new mainclass();


x1.display();

// TODO add your handling code here:


}

You might also like