0% found this document useful (0 votes)
15 views

FINALS

Uploaded by

Envy n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

FINALS

Uploaded by

Envy n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

import java.awt.

Color;

import java.awt.Font;

import java.awt.HeadlessException;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.*;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class Add_module {

public static void main(String[] args) {

Connection con = dbconnect.MySQL();

Color lightred = new Color(255, 51, 51);

JFrame frame = new JFrame("Blythrenze M. Rama - FINALS");

JPanel panel = new JPanel();

JTextField fid = new JTextField();

JTextField f1 = new JTextField();

JTextField f2 = new JTextField();

JTextField f3 = new JTextField();


JButton btn1 = new JButton("Add Record");

JButton btn2 = new JButton("Clear");

JButton btn3 = new JButton("Exit");

JButton btn4 = new JButton("Delete");

JButton btn5 = new JButton("Search");

JLabel li = new JLabel("ID");

JLabel l1 = new JLabel("Firstname");

JLabel l2 = new JLabel("Lastname");

JLabel l3 = new JLabel("Address");

panel.setBackground(lightred);

frame.setSize(500, 400);

frame.setVisible(true);

panel.setLayout(null);

fid.setBounds(190, 50, 200, 30);

f1.setBounds(190, 100, 200, 30);

f2.setBounds(190,150, 200, 30);

f3.setBounds(190, 200, 200, 30);

li.setBounds(100, 50, 100, 30);

li.setFont(new Font("Arial",Font.BOLD,18));

l1.setBounds(100, 100, 100, 30);

l1.setFont(new Font("Arial",Font.BOLD,18));

l2.setBounds(100, 150, 100, 30);

l2.setFont(new Font("Arial",Font.BOLD,18));

l3.setBounds(100, 200,100, 30);

l3.setFont(new Font("Arial",Font.BOLD,18));

btn5.setBounds(70, 300, 100, 40);

btn4.setBounds(250, 250, 100, 40);

btn1.setBounds(120,250, 100, 40);

btn2.setBounds(190, 300, 100, 40);


btn3.setBounds(310, 300, 100, 40);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(panel);

panel.add(f1);

panel.add(li);

panel.add(l1);

panel.add(l2);

panel.add(f2);

panel.add(l3);

panel.add(f3);

panel.add(fid);

panel.add(btn1);

panel.add(btn2);

panel.add(btn3);

panel.add(btn4);

panel.add(btn5);

btn1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ex){

String Firstname = f1.getText();

String Lastname = f2.getText();

String Address = f3.getText();

try {

PreparedStatement psmt = con.prepareStatement("Insert into


rama_table(Firstname,Lastname,Address) values (?,?,?)");
psmt.setString(1, Firstname);

psmt.setString(2, Lastname);

psmt.setString(3, Address);

psmt.executeUpdate();

JOptionPane.showMessageDialog(null, "Record Succcessfully Added");

} catch (SQLException ex1) {

Logger.getLogger(Add_module.class.getName()).log(Level.SEVERE, null, ex1);

});

btn2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ex){

f1.setText(null);

f2.setText(null);

f3.setText(null);

});

btn3.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ex){


System.exit(0);

});

btn5.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ex){

String id = fid.getText();

try {

PreparedStatement psmt = con.prepareStatement("Select * from rama_table where ID ="+id);

ResultSet rs = psmt.executeQuery();

if(rs.next()){

f1.setText(rs.getString("Firstname"));

f2.setText(rs.getString("Lastname"));

f3.setText(rs.getString("Address"));

JOptionPane.showMessageDialog(null, "Record Found");

} catch (SQLException ex1) {

Logger.getLogger(Add_module.class.getName()).log(Level.SEVERE, null, ex1);

});

btn4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ex){

String id = fid.getText();

try {

PreparedStatement psmt = con.prepareStatement("DELETE from rama_table where ID ="+id);

psmt.executeUpdate();

fid.setText(null);

f1.setText(null);

f2.setText(null);

f3.setText(null);

JOptionPane.showMessageDialog(null, "Record Succefully Deleted");

} catch (SQLException ex1) {

Logger.getLogger(Add_module.class.getName()).log(Level.SEVERE, null, ex1);

});

}
DB CONNECT

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author Diaz

*/

public class dbconnect {

public static Connection MySQL() {

Connection Mysql = null;

try{

Class.forName("com.mysql.jdbc.Driver");

Mysql = DriverManager.getConnection("jdbc:mysql://localhost:3306/rama_record","root","");

}catch(ClassNotFoundException ex) {
ex.printStackTrace();

} catch (SQLException ex) {

Logger.getLogger(dbconnect.class.getName()).log(Level.SEVERE, null, ex);

return Mysql;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy