CRUD Java Netbeans# MainMenu Connect MySQL Server Xampp
( MAIN MENU HOSPITAL ) PROGRAM SAMPLE
Java Apache Netbeans # WITH MYSQL SERVER XAMPP
Bismillah
Bismillah
Pada tahap awal ini untuk membuat aplikasi Java # with MySql Server Xampp kita membutuhkan beberapa toll dan form diantara nya adalah : Form Registration - Form PatientRec.
- Apache Netbeans IDE 14 Link Download
Database dengan nama : medical .
Tabel - tabel yang digunakan dalam database medical antara lain :
TABLE `users`
TABLE `registration
TABLE `services`
TABLE `patientregistration`
TABLE `doctor`
TABLE `room`
Link Download Database
Dengan Sql Query sebagai berikut : medical.sql
CREATE TABLE `users` (
`user_name` varchar(20) NOT NULL,
`password` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
CREATE TABLE `registration` (
`name` varchar(20) DEFAULT NULL,
`user_name` varchar(20) NOT NULL,
`password` varchar(20) DEFAULT NULL,
`email_id` varchar(30) DEFAULT NULL,
`contact_no` int(15) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
CREATE TABLE `services` (
`ServiceName` varchar(25) DEFAULT NULL,
`ServiceDate` date DEFAULT NULL,
`PatientID` int(10) DEFAULT NULL,
`ServiceCharges` int(10) DEFAULT NULL,
`ServiceID` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
- TABLE `patientregistration`
----------------------------------
CREATE TABLE `patientregistration` (
`PatientID` int(10) NOT NULL,
`PatientName` varchar(25) DEFAULT NULL,
`FatherName` varchar(25) DEFAULT NULL,
`Email` varchar(30) DEFAULT NULL,
`ContactNo` varchar(15) DEFAULT NULL,
`Age` int(2) DEFAULT NULL,
`Remarks` varchar(100) DEFAULT NULL,
`Gen` varchar(10) DEFAULT NULL,
`BG` varchar(3) DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
TABLE `doctor`
----------------------------------
CREATE TABLE `doctor` (
`DoctorID` int(10) NOT NULL,
`DoctorName` varchar(25) DEFAULT NULL,
`FatherName` varchar(25) DEFAULT NULL,
`Email` varchar(50) DEFAULT NULL,
`ContacNo` varchar(15) DEFAULT NULL,
`Qualifications` varchar(50) DEFAULT NULL,
`Gender` varchar(1) DEFAULT NULL,
`BloodGroup` varchar(5) DEFAULT NULL,
`DateOfJoining` date DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
TABLE `room`
----------------------------------
CREATE TABLE `room` (
`RoomNo` int(5) NOT NULL,
`RoomType` varchar(15) DEFAULT NULL,
`RoomCharges` int(10) DEFAULT NULL,
`RoomStatus` varchar(15) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
---------------------------------------------------------------------------------------------------
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL ) PROGRAM SAMPLE yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
( MAIN MENU HOSPITAL / MENU USERS)
( MAIN MENU HOSPITAL / MENU PASIEN)
( MAIN MENU HOSPITAL / MENU ROOM)
( MAIN MENU HOSPITAL / MENU ROOM)
Source code MainMenu.java
package hospital;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javax.swing.Timer;
/**
*
* @author ASUS
*/
public class MenuMain extends javax.swing.JFrame {
/**
* Creates new form MenuMain
*/
public MenuMain() {
initComponents();
Tampil_Jam();
Tampil_Tanggal() ;
}
public void Tampil_Jam(){
ActionListener taskPerformer = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
String nol_jam = "", nol_menit = "",nol_detik = "";
java.util.Date dateTime = new java.util.Date();
int nilai_jam = dateTime.getHours();
int nilai_menit = dateTime.getMinutes();
int nilai_detik = dateTime.getSeconds();
if(nilai_jam <= 9) nol_jam= "0";
if(nilai_menit <= 9) nol_menit= "0";
if(nilai_detik <= 9) nol_detik= "0";
String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);
jLabel_Jam.setText(jam+":"+menit+":"+detik+"");
}
};
new Timer(1000, taskPerformer).start();
}
public void Tampil_Tanggal() {
java.util.Date tglsekarang = new java.util.Date();
SimpleDateFormat smpdtfmt = new SimpleDateFormat("dd MMMMMMMMM yyyy", Locale.getDefault());
String tanggal = smpdtfmt.format(tglsekarang);
jLabel_Tanggal.setText(tanggal);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NewUser ob1=new NewUser();
ob1.setVisible(true);
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Registration ob1=new Registration();
ob1.setVisible(true);
}
private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Services ob1=new Services();
ob1.setVisible(true);
}
private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
FormAbout ob1=new FormAbout();
ob1.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ChangePassword ob1=new ChangePassword();
ob1.setVisible(true);
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RecordUser ob1=new RecordUser();
ob1.setVisible(true);
}
private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Room ob1=new Room();
ob1.setVisible(true);
}
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Doctor ob1=new Doctor();
ob1.setVisible(true);
}
---------------------------------------------------------------------------------------------------
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL / MENU USERS)
yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
NEW USERS
Source code NewUsers.java
package hospital;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author ASUS
*/
public class NewUser extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form NewUser
*/
public NewUser() {
initComponents();
}
private void reset()
{
txtName.setText("");
txtUsername.setText("");
jPassword.setText("");
txtEmailid.setText("");
txtContactno.setText("");
Save.setEnabled(true);
Delete.setEnabled(false);
Update.setEnabled(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void NewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
reset();
}
private void SaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
if (txtName.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter name");
return;
}
if (txtUsername.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter user name");
return;
}
if (jPassword.equals("")) {
JOptionPane.showMessageDialog( this, "Please enter password");
return;
}
if (txtContactno.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter contact no.");
return;
}
if (txtEmailid.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter email id");
return;
}
Statement stmt;
stmt= con.createStatement();
String sql1="Select user_name from registration where user_name= '" + txtUsername.getText() + "'";
rs=stmt.executeQuery(sql1);
if(rs.next()){
JOptionPane.showMessageDialog( this, "User name already exists");
txtUsername.setText("");
return;
}
String sql= "insert into registration(user_name,password,name,email_id,contact_no)values('"+ txtUsername.getText() + "','" + jPassword.getText() + "','" + txtName.getText() + "','" + txtEmailid.getText() + "','" + txtContactno.getText() + "')";
pst=con.prepareStatement(sql);
pst.execute();
String sql2= "insert into users(user_name,password)values('" + txtUsername.getText() + "','" + jPassword.getText() + "')";
pst=con.prepareStatement(sql2);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully Registered");
Save.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
} // TODO add your handling code here:
}
private void UpdateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
String sql= "update registration set password='" + jPassword.getText() + "',name='" + txtName.getText() + "',email_id='" + txtEmailid.getText() + "',contact_no='" + txtContactno.getText() + "' where user_name='" + txtUsername.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
String sql2= "update users set password='" + jPassword.getText() + "' where user_name='" + txtUsername.getText() + "'";
pst=con.prepareStatement(sql2);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully updated","User info",JOptionPane.INFORMATION_MESSAGE);
Update.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
} // TODO add your handling code here:
}
private void DeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
if (P==0)
{
con=Connect.ConnectDB();
String sql= "delete from registration where user_name = '" + txtUsername.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
String sql1= "delete from Users where user_name = '" + txtUsername.getText() + "'";
pst=con.prepareStatement(sql1);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully deleted");
reset();
}
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
// TODO add your handling code here:
}
private void GetDataActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
RecordUser ob1 =new RecordUser();
ob1.setVisible(true);
// TODO add your handling code here:
}
private void BackActionPerformed(java.awt.event.ActionEvent evt) {
MenuMain ob1 =new MenuMain();
ob1.setVisible(true);
}
Source code ChangePassword.java
package hospital;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author ASUS
*/
public class ChangePassword extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form ChangePassword
*/
public ChangePassword() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void BtnChangePassActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
String Newpass=String.valueOf(psdn.getText());
String ConfPass=String.valueOf(psdc.getText());
String OldPass=String.valueOf(psdo.getText());
String uName=txtUsername.getText();
if (uName.equals("")) {
JOptionPane.showMessageDialog( this, "Please enter a username");
return;
} else if (OldPass.equals("")) {
JOptionPane.showMessageDialog( this, "Please enter a old password");
return;
} else if (Newpass.equals("")) {
JOptionPane.showMessageDialog( this, "Please enter a new password");
return;
} else if (ConfPass.equals("")) {
JOptionPane.showMessageDialog( this, "Please enter a confirmed password");
return;
}
else if (Newpass.length()< 5) {
JOptionPane.showMessageDialog(this,"The New Password Should be of Atleast 5 Characters");
return;
}
else if ((Newpass).equals(OldPass)) {
JOptionPane.showMessageDialog(this, "Password is same..Re-enter new password");
return;
}
else if (!(Newpass).equals(ConfPass)) {
JOptionPane.showMessageDialog(this,"New Password doesn't match with Confirmed Password");
return;
}
con=Connect.ConnectDB();
String sql= "select user_name,password from users where user_name='" + txtUsername.getText() + "' and password= '" + psdo.getText() + "'";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
while(rs.next())
{
String usrname = rs.getString("user_name").trim();
String passwd = rs.getString("password").trim();
if(uName.equals(usrname) && OldPass.equals(passwd))
{
con=Connect.ConnectDB();
String sql1= "update users set password= '" + Newpass + "' where user_name= '" + uName + "' and password = '" + OldPass + "'";
Statement stmt = con.createStatement();
stmt.execute(sql1.toString());
stmt.close();
JOptionPane.showMessageDialog(this,"Password Successfully Changed");
this.dispose();
return;
}
else
{
JOptionPane.showMessageDialog(this,"invalid user name or password");
txtUsername.setText("");
psdo.setText("");
psdn.setText("");
psdc.setText("");
return;
}
}
}catch(SQLException | HeadlessException ex){
JOptionPane.showMessageDialog(this,ex);
} // TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Login ob1 =new Login();
ob1.setVisible(true);
}
Source code LoginDetail.java
package hospital;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
/**
*
* @author ASUS
*/
public class RecordUser extends javax.swing.JFrame {
Connection con = null;
ResultSet rs = null;
PreparedStatement pst = null;
/**
* Creates new form RecordUser
*/
public RecordUser() {
initComponents();
con = Connect.ConnectDB();
Get_Data();
}
private void Get_Data() {
String sql = "select name as 'Name', user_name as 'User Name',password,contact_no as 'Contact No',email_id as 'Email ID' from registration";
try {
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked"
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
try {
con = Connect.ConnectDB();
int row = jTable1.getSelectedRow();
String table_click = jTable1.getModel().getValueAt(row, 1).toString();
String sql = "select * from registration where user_name= '" + table_click + "'";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
if (rs.next()) {
this.hide();
NewUser ob1 = new NewUser();
ob1.setVisible(true);
String add1 = rs.getString("user_name");
ob1.txtUsername.setText(add1);
String add2 = rs.getString("password");
ob1.jPassword.setText(add2);
String add3 = rs.getString("name");
ob1.txtName.setText(add3);
String add4 = rs.getString("contact_no");
ob1.txtContactno.setText(add4);
String add5 = rs.getString("email_id");
ob1.txtEmailid.setText(add5);
ob1.Save.setEnabled(false);
ob1.Delete.setEnabled(true);
ob1.Update.setEnabled(true);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex);
} // TODO add your handling code here:
}
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL / MENU PASIEN)
yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
REGISTRATION
PATIENTRECORD
SERVICE
SERVICE RECORD
Source code Registrtion.java
package hospital;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author ASUS
*/
public class Registration extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Registration
*/
public Registration() {
initComponents();
}
private void Reset()
{
txtId.setText("");
txtName.setText("");
txtFname.setText("");
txtContact.setText("");
txtAdd.setText("");
txtAge.setText("");
txtEmail.setText("");
txtInfo.setText("");
cmbBG.setSelectedIndex(-1);
cmbGender.setSelectedIndex(-1);
btnSave.setEnabled(true);
btnUpdate.setEnabled(false);
btnDelete.setEnabled(false);
txtId.requestDefaultFocus();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Reset();
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
if (txtId.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter patient id","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtName.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter patient name","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtFname.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter Father's name","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtAdd.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter address","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtContact.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter contact no.","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtAge.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter age","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (cmbGender.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog( this, "Please select gender","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (cmbBG.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog( this, "Please select blood group","Error", JOptionPane.ERROR_MESSAGE);
return;
}
Statement stmt;
stmt= con.createStatement();
String sql1="Select PatientID from PatientRegistration where PatientID= '" + txtId.getText() + "'";
rs=stmt.executeQuery(sql1);
if(rs.next()){
JOptionPane.showMessageDialog( this, "Patient ID already exists","Error", JOptionPane.ERROR_MESSAGE);
txtId.setText("");
txtId.requestDefaultFocus();
return;
}
String sql= "insert into PatientRegistration(PatientID,Patientname,FatherName,Email,ContactNo,Age,Remarks,Gen,BG,Address)values('"+ txtId.getText() + "','"+ txtName.getText() + "','"+ txtFname.getText() + "','"+ txtEmail.getText() + "','"+ txtContact.getText() + "'," + txtAge.getText() + ",'"+ txtInfo.getText() + "','" + cmbGender.getSelectedItem() + "','"+ cmbBG.getSelectedItem() + "','" + txtAdd.getText() + "')";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully Registered","Patient",JOptionPane.INFORMATION_MESSAGE);
btnSave.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
String sql= "update PatientRegistration set Patientname='"+ txtName.getText() + "',Fathername='"+ txtFname.getText() + "',Email='"+ txtEmail.getText() + "',ContactNo='"+ txtContact.getText() + "',Age=" + txtAge.getText() + ",Remarks='"+ txtInfo.getText() + "',Gen='" + cmbGender.getSelectedItem() + "',BG='"+ cmbBG.getSelectedItem() + "',Address='" + txtAdd.getText() + "' where PatientID='" + txtId.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully updated","Record",JOptionPane.INFORMATION_MESSAGE);
btnUpdate.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
} // TODO add your handling code here:
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
if (P==0)
{
con=Connect.ConnectDB();
String sql= "delete from patientregistration where PatientID = '" + txtId.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully deleted","Record",JOptionPane.INFORMATION_MESSAGE);
Reset();
}
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
} // TODO add your handling code here:
}
private void btnGetDataActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
PatientRec frm=new PatientRec();
frm.setVisible(true); // TODO add your handling code here:
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuMain ob1 =new MenuMain();
ob1.setVisible(true);
}
Source code PatientRec.java
package hospital;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
/**
*
* @author ASUS
*/
public class PatientRec extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form PatientRec
*/
public PatientRec() {
initComponents();
con= Connect.ConnectDB();
Get_Data();
}
private void Get_Data(){
String sql="select PatientID as 'Patient ID', PatientName as 'Patient Name',FatherName as 'Father Name',Address,ContactNo as 'Contact No',Email as 'Email ID',Age,Gen as 'Gender',BG as 'Blood Group',Remarks from Patientregistration";
try{
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
int row= jTable1.getSelectedRow();
String table_click= jTable1.getModel().getValueAt(row, 0).toString();
String sql= "select * from PatientRegistration where PatientID = '" + table_click + "'";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
if(rs.next()){
this.hide();
Registration frm = new Registration();
frm.setVisible(true);
String add1=rs.getString("PatientID");
frm.txtId.setText(add1);
String add2=rs.getString("Patientname");
frm.txtName.setText(add2);
String add3=rs.getString("Fathername");
frm.txtFname.setText(add3);
String add5=rs.getString("Email");
frm.txtEmail.setText(add5);
int add6 = rs.getInt("Age");
String add= Integer.toString(add6);
frm.txtAge.setText(add);
String add7=rs.getString("Remarks");
frm.txtInfo.setText(add7);
String add9=rs.getString("BG");
frm.cmbBG.setSelectedItem(add9);
String add11=rs.getString("Gen");
frm.cmbGender.setSelectedItem(add11);
String add15=rs.getString("Address");
frm.txtAdd.setText(add15);
String add16=rs.getString("ContactNo");
frm.txtContact.setText(add16);
frm.btnUpdate.setEnabled(true);
frm.btnDelete.setEnabled(true);
frm.btnSave.setEnabled(false);
}
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex);
}
}
Source code Services.java
package hospital;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
import java.sql.*;
import java.sql.Statement;
import java.awt.*;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.Scanner;
import javax.swing.table.DefaultTableModel;
/**
*
* @author ASUS
*/
public class Services extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Services
*/
public Services() {
initComponents();
setLocationRelativeTo(null);
txtServiceID.setVisible(false);
Get_Data1();
}
private void Get_Data1(){
try{
con=Connect.ConnectDB();
String sql="select PatientID as 'Patient ID', PatientName as 'Patient Name' from Patientregistration order by PatientName";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
tblPatient.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
private void Reset()
{
txtPatient.setText("");
txtServiceID.setText("");
txtPatientName.setText("");
txtServiceDate.setText("");
txtServiceName.setText("");
txtServiceCharges.setText("");
txtSaves.setEnabled(true);
txtUpdated.setEnabled(false);
txtDeleted.setEnabled(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void tblPatientMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
int row= tblPatient.getSelectedRow();
String table_click= tblPatient.getModel().getValueAt(row, 0).toString();
String sql= "select * from PatientRegistration where PatientID = '" + table_click + "'";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
if(rs.next()){
String add1=rs.getString("PatientID");
txtPatient.setText(add1);
String add2=rs.getString("Patientname");
txtPatientName.setText(add2);
}
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void txtNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Reset();
}
private void txtSavesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
if (txtServiceName.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter service name");
return;
}
if (txtServiceDate.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter service date");
return;
}
if (txtPatient.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please retrieve patient id");
return;
}
if (txtServiceCharges.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter service charges");
return;
}
String sql= "insert into Services(ServiceName,ServiceDate,PatientID,ServiceCharges)values('"+ txtServiceName.getText() + "','"+ txtServiceDate.getText()+ "','" + txtPatient.getText() + "'," + txtServiceCharges.getText() + ")";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully saved","Record",JOptionPane.INFORMATION_MESSAGE);
txtSaves.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void txtUpdatedActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
String sql= "update Services set ServiceName='" + txtServiceName.getText() +"',ServiceDate='" + txtServiceDate.getText()+ "',PatientID='" + txtPatient.getText() + "',ServiceCharges='" + txtServiceCharges.getText() + "' where ServiceID='" + txtServiceID.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully updated");
txtUpdated.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void txtDeletedActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
if (P==0)
{
con=Connect.ConnectDB();
String sql= "delete from Services where ServiceID = " + txtServiceID.getText() + "";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully deleted");
Reset();
}
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void txtGetDataActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
ServicesRec frm= new ServicesRec();
frm.setVisible(true);
}
private void txtBackActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuMain ob1 =new MenuMain();
ob1.setVisible(true);
}
Source code ServicesRec.java
package hospital;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
import java.sql.*;
import java.sql.Statement;
import java.awt.*;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.Scanner;
import javax.swing.table.DefaultTableModel;
/**
*
* @author ASUS
*/
public class ServicesRec extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form ServicesRec
*/
public ServicesRec() {
initComponents();
con= Connect.ConnectDB();
Get_Data();
}
private void Get_Data(){
String sql="select ServiceID as 'Service ID', ServiceName as 'Service Name',ServiceDate as 'Service Date',PatientRegistration.PatientID as 'Patient ID',PatientName as 'Patient Name',ServiceCharges as 'Service Charges' from PatientRegistration,Services where Services.PatientID=PatientRegistration.PatientID order by PatientName";
try{
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
txtTable.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
e.printStackTrace();
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void txtTableMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
con = Connect.ConnectDB();
int row = txtTable.getSelectedRow();
String table_click = txtTable.getModel().getValueAt(row, 0).toString();
String sql="Select * from PatientRegistration,Services where Services.PatientID=PatientRegistration.PatientID and ServiceID=" + table_click + "";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
if(rs.next()){
this.hide();
Services frm = new Services();
frm.setVisible(true);
String add1=rs.getString("ServiceName");
frm.txtServiceName.setText(add1);
String add2=rs.getString("ServiceDate");
frm.txtServiceDate.setText(add2);
String add3=rs.getString("PatientName");
frm.txtPatientName.setText(add3);
String add4=rs.getString("PatientID");
frm.txtPatient.setText(add4);
int add5 = rs.getInt("ServiceID");
String add6= Integer.toString(add5);
frm.txtServiceID.setText(add6);
int add7 = rs.getInt("ServiceCharges");
String add8= Integer.toString(add7);
frm.txtServiceCharges.setText(add8);
frm.txtSaves.setEnabled(false);
frm.txtDeleted.setEnabled(true);
frm.txtUpdated.setEnabled(true);
}
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex);
}
}
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL / MENU DOCTOR)
yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
DOCTOR
Source code Doctor.java
package hospital;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import java.text.SimpleDateFormat;
/**
*
* @author ASUS
*/
public class Doctor extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Doctor
*/
public Doctor() {
initComponents();
}
private void reset()
{
txtId.setText("");
txtName.setText("");
txtFname.setText("");
txtC.setText("");
txtAd.setText("");
txtQ.setText("");
txtE.setText("");
txtD.setText("");
cmbB.setSelectedIndex(-1);
cmbG.setSelectedIndex(-1);
btnSave.setEnabled(true);
btnUpdate.setEnabled(false);
btnDelete.setEnabled(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
reset();
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
if (txtId.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter doctor id","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtName.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter doctor name","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtFname.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter Father's name","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtAd.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter address","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtC.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter contact no.","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtQ.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter qualifications","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (cmbG.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog( this, "Please select gender","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (cmbB.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog( this, "Please select blood group","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtD.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter joining date","Error", JOptionPane.ERROR_MESSAGE);
return;
}
Statement stmt;
stmt= con.createStatement();
String sql1="Select DoctorID from Doctor where DoctorID= '" + txtId.getText() + "'";
rs=stmt.executeQuery(sql1);
if(rs.next()){
JOptionPane.showMessageDialog( this, "Doctor ID already exists","Error", JOptionPane.ERROR_MESSAGE);
txtId.setText("");
return;
}
String sql= "insert into Doctor(DoctorID,Doctorname,FatherName,Email,ContacNo,Qualifications,Gender,BloodGroup,DateOfJoining,Address)values('"+ txtId.getText() + "','"+ txtName.getText() + "','"+ txtFname.getText() + "','"+ txtE.getText() + "','"+ txtC.getText() + "','"+ txtQ.getText() + "','"+ cmbG.getSelectedItem() + "','"+ cmbB.getSelectedItem() + "','" + txtD.getText() + "','" + txtAd.getText() + "')";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully saved","Doctor Record",JOptionPane.INFORMATION_MESSAGE);
btnSave.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
String sql= "update Doctor set Doctorname='" + txtName.getText() + "',FatherName='" + txtFname.getText() + "',Email='" + txtE.getText() + "',ContacNo='"+ txtC.getText() + "',Qualifications='"+ txtQ.getText() + "',Gender='" + cmbG.getSelectedItem() + "',BloodGroup='"+ cmbB.getSelectedItem() + "',DateOfJoining='" + txtD.getText() + "',Address='" + txtAd.getText() + "' where DoctorID='" + txtId.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully updated");
btnUpdate.setEnabled(false);
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
if (P==0)
{
con=Connect.ConnectDB();
String sql= "delete from Doctor where DoctorID = '" + txtId.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully deleted","Record",JOptionPane.INFORMATION_MESSAGE);
reset();
}
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnGetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
DocRec frm=new DocRec();
frm.setVisible(true);
}
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuMain ob1 =new MenuMain();
ob1.setVisible(true);
}
Source code DocRec.java
package hospital;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
/**
*
* @author ASUS
*/
public class DocRec extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form DocRec
*/
public DocRec() {
initComponents();
con= Connect.ConnectDB();
Get_Data();
}
private void Get_Data(){
String sql="select DoctorID as 'Doctor ID', DoctorName as 'Doctor Name',FatherName as 'Father Name',Address,ContacNo as 'Contact No',Email as 'Email ID',Qualifications,Gender,BloodGroup as 'Blood Group',DateOfJoining as 'Joining Date' from Doctor order by DoctorName";
try{
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
int row= jTable1.getSelectedRow();
String table_click= jTable1.getModel().getValueAt(row, 0).toString();
String sql= "select * from Doctor where DoctorID = '" + table_click + "'";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
if(rs.next()){
this.hide();
Doctor frm = new Doctor();
frm.setVisible(true);
String add1=rs.getString("DoctorID");
frm.txtId.setText(add1);
String add2=rs.getString("Doctorname");
frm.txtName.setText(add2);
String add3=rs.getString("Fathername");
frm.txtFname.setText(add3);
String add5=rs.getString("Email");
frm.txtE.setText(add5);
String add6=rs.getString("Qualifications");
frm.txtQ.setText(add6);
String add9=rs.getString("BloodGroup");
frm.cmbB.setSelectedItem(add9);
String add11=rs.getString("Gender");
frm.cmbG.setSelectedItem(add11);
String add14=rs.getString("DateOfJoining");
frm.txtD.setText(add14);
String add15=rs.getString("Address");
frm.txtAd.setText(add15);
String add16=rs.getString("ContacNo");
frm.txtC.setText(add16);
frm.btnUpdate.setEnabled(true);
frm.btnDelete.setEnabled(true);
frm.btnSave.setEnabled(false);
}
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex);
}
}
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL / MENU ROOMS)
yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
ROOMS
Berikut tampilan Design Form pada ( MAIN MENU HOSPITAL / MENU HELPS)
yang kita gunakan dari Form Login,Form Menu dan Form lainnya :
FORM ABOUT
Source code Room.java
package hospital;
import java.awt.HeadlessException;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
/**
*
* @author ASUS
*/
public class Room extends javax.swing.JFrame {
Connection con=null;
ResultSet rs=null;
PreparedStatement pst=null;
/**
* Creates new form Room
*/
public Room() {
initComponents();
con= Connect.ConnectDB();
Get_Data();
setLocationRelativeTo(null);
}
private void Get_Data(){
String sql="select RoomNo as 'Room No.',RoomType as 'Room Type', RoomCharges as 'Room Charges',RoomStatus as 'Room Status' from Room";
try{
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
Room_table.setModel(DbUtils.resultSetToTableModel(rs));
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
private void Reset()
{
txtRoomNo.setText("");
txtRoomCharges.setText("");
cmbRoomType.setSelectedIndex(-1);
btnSave.setEnabled(true);
btnDelete.setEnabled(false);
btnUpdate.setEnabled(false);
txtRoomNo.requestDefaultFocus();
Get_Data();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Reset();
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
if (txtRoomNo.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter room no.","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (cmbRoomType.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog( this, "Please select room type","Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtRoomCharges.getText().equals("")) {
JOptionPane.showMessageDialog( this, "Please enter room Charges","Error", JOptionPane.ERROR_MESSAGE);
return;
}
Statement stmt;
stmt= con.createStatement();
String sql1="Select RoomNo from Room where RoomNo= '" + txtRoomNo.getText() + "'";
rs=stmt.executeQuery(sql1);
if(rs.next()){
JOptionPane.showMessageDialog( this, "Room No. already exists","Error", JOptionPane.ERROR_MESSAGE);
txtRoomNo.setText("");
txtRoomNo.requestDefaultFocus();
return;
}
String sql= "insert into Room(RoomNo,RoomType,RoomCharges,RoomStatus)values('"+ txtRoomNo.getText() + "','"+ cmbRoomType.getSelectedItem() + "'," + txtRoomCharges.getText() + ",'Vacant')";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully saved","Room Record",JOptionPane.INFORMATION_MESSAGE);
btnSave.setEnabled(false);
Get_Data();
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
String sql= "update Room set Roomtype='"+ cmbRoomType.getSelectedItem() + "',RoomCharges=" + txtRoomCharges.getText() + " where RoomNo='" + txtRoomNo.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully updated","Room Record",JOptionPane.INFORMATION_MESSAGE);
btnUpdate.setEnabled(false);
Get_Data();
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete ?","Confirmation",JOptionPane.YES_NO_OPTION);
if (P==0)
{
con=Connect.ConnectDB();
String sql= "delete from Room where RoomNo = '" + txtRoomNo.getText() + "'";
pst=con.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this,"Successfully deleted","Record",JOptionPane.INFORMATION_MESSAGE);
Reset();
}
}catch(HeadlessException | SQLException ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void btnGetDataActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Get_Data();
}
private void Room_tableMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try{
con=Connect.ConnectDB();
int row= Room_table.getSelectedRow();
String table_click= Room_table.getModel().getValueAt(row, 0).toString();
String sql= "select * from Room where RoomNo = '" + table_click + "'";
pst=con.prepareStatement(sql);
rs= pst.executeQuery();
if(rs.next()){
String add1=rs.getString("RoomNo");
txtRoomNo.setText(add1);
String add2=rs.getString("RoomType");
cmbRoomType.setSelectedItem(add2);
int add3 = rs.getInt("RoomCharges");
String add4= Integer.toString(add3);
txtRoomCharges.setText(add4);
btnUpdate.setEnabled(true);
btnDelete.setEnabled(true);
btnSave.setEnabled(false);
}
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MenuMain ob1 =new MenuMain();
ob1.setVisible(true);
}
Sekilas Hasil Desain Form saat di Running Exsecuse
Komentar
Posting Komentar