You are designing a simple database connected application that contains one form
ID: 3816891 • Letter: Y
Question
You are designing a simple database connected application that contains one form and one table. The purpose of the application is to allow the user to enter new books into the library's inventory.
Part 1
- Briefly describe your table. You discussion should include attributes, justification, and data type for each field. You should have at least five fields of your choosing.
- Write the SQL command to create the table that you described above.
- Write the SQL command to insert a record into the table.
- Write the SQL command to delete a record from the table.
- Write at least 2 conditional SELECT queries.
Part 2
- Design a simple interface using the drag and drop tools in NetBeans to support inserting a record into your database table.
Explanation / Answer
please find the java code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class RegistrationForm extends JFrame implements ActionListener
{
JLabel label1, label2, label3, label4, label5, label6, label7, label8;
JTextField textfield1, textfield2, textfield5, textfield6, textfield7;
JButton button1, button2;
JPasswordField password, confirmpassword;
RegistrationForm()
{
setVisible(true);
setSize(700, 700);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("User Registration Form");
label1 = new JLabel("User Registration Form");
label1.setForeground(Color.blue);
label1.setFont(new Font("Times New Roman", Font.BOLD, 20));
label2 = new JLabel("Enter Name:");
label3 = new JLabel("Email ID:");
label4 = new JLabel("Passowrd:");
label5 = new JLabel("Confirm Password:");
label6 = new JLabel("Country:");
label7 = new JLabel("State:");
label8 = new JLabel("Phone No:");
textfield1 = new JTextField();
textfield2 = new JTextField();
password = new JPasswordField();
confirmpassword = new JPasswordField();
textfield5 = new JTextField();
textfield6 = new JTextField();
textfield7 = new JTextField();
button1 = new JButton("Submit Details");
button2 = new JButton("Clear Details");
button1.addActionListener(this);
button2.addActionListener(this);
label1.setBounds(100, 30, 400, 30);
label2.setBounds(80, 70, 200, 30);
label3.setBounds(80, 110, 200, 30);
label4.setBounds(80, 150, 200, 30);
label5.setBounds(80, 190, 200, 30);
label6.setBounds(80, 230, 200, 30);
label7.setBounds(80, 270, 200, 30);
label8.setBounds(80, 310, 200, 30);
textfield1.setBounds(300, 70, 200, 30);
textfield2.setBounds(300, 110, 200, 30);
password.setBounds(300, 150, 200, 30);
confirmpassword.setBounds(300, 190, 200, 30);
textfield5.setBounds(300, 230, 200, 30);
textfield6.setBounds(300, 270, 200, 30);
textfield7.setBounds(300, 310, 200, 30);
button1.setBounds(50, 350, 100, 30);
button2.setBounds(170, 350, 100, 30);
add(label1);
add(label2);
add(textfield1);
add(label3);
add(textfield2);
add(label4);
add(password);
add(label5);
add(confirmpassword);
add(label6);
add(textfield5);
add(label7);
add(textfield6);
add(label8);
add(textfield7);
add(button1);
add(button2);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button1)
{
int x = 0;
String s1 = textfield1.getText();
String s2 = textfield2.getText();
char[] s3 = password.getPassword();
char[] s4 = confirmpassword.getPassword();
String s8 = new String(s3);
String s9 = new String(s4);
String s5 = textfield5.getText();
String s6 = textfield6.getText();
String s7 = textfield7.getText();
if (s8.equals(s9))
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "username for the DB ", "password for the DB");
PreparedStatement ps = con.prepareStatement("insert into employee values(?,?,?,?,?,?)");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s8);
ps.setString(4, s5);
ps.setString(5, s6);
ps.setString(6, s7);
ResultSet rs = ps.executeQuery();
x++;
if (x > 0)
{
JOptionPane.showMessageDialog(button1, "Data inserted successfully in the table");
}
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else
{
JOptionPane.showMessageDialog(button1, "Password Does Not Match");
}
}
else
{
textfield1.setText("");
textfield2.setText("");
password.setText("");
password.setText("");
textfield5.setText("");
textfield6.setText("");
textfield7.setText("");
}
}
public static void main(String args[])
{
new RegistrationForm();
}
}
change the URL for JDBC driver.and provide the correct username and password for the DB
create table employee(
username varchar2(100),
emailid varchar2(100),
password varchar2(100),
country varchar2(100),
state varchar2(100),
phone varchar2(100)
);
insert into employee (username, emailid, password, country , state , phone ) values ('john','john@email','john*1234','India','India','1234')
insert into employee (username, emailid, password, country , state , phone ) values ('johnny','johnny@email','johnny*1234','US','New York','1234')
delete from employee where username ='john'
delete from employee where username ='johnny'
select * from employee where username ='john'
select * from employee where username ='john'
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.