Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We are asked to combine/modify this two set of codes so that the Login.java will compare its input through its GUI to the JDBC that

We are asked to combine/modify this two set of codes so that the Login.java will compare its input through its GUI to the JDBC that has the table ACC_INFO and has this data: image text in transcribed Login.java has this code: ________________________________ import javax.swing.*; import java.awt.*; import java.awt.event.*; final class LoginFrame extends JFrame implements ActionListener { Container container = getContentPane(); JLabel userLabel = new JLabel("USERNAME"); JLabel passwordLabel = new JLabel("PASSWORD"); JTextField userTextField = new JTextField(); JPasswordField passwordField = new JPasswordField(); JButton loginButton = new JButton("LOGIN"); JButton resetButton = new JButton("RESET"); JCheckBox showPassword = new JCheckBox("Show Password"); LoginFrame() { setLayoutManager(); setLocationAndSize(); addComponentsToContainer(); addActionEvent(); } public void setLayoutManager() { container.setLayout(null); } public void setLocationAndSize() { userLabel.setBounds(50, 50, 100, 30); passwordLabel.setBounds(50, 120, 100, 30); userTextField.setBounds(150, 50, 150, 30); passwordField.setBounds(150, 120, 150, 30); showPassword.setBounds(150, 150, 150, 30); loginButton.setBounds(50, 200, 100, 30); resetButton.setBounds(200, 200, 100, 30); } public void addComponentsToContainer() { container.add(userLabel); container.add(passwordLabel); container.add(userTextField); container.add(passwordField); container.add(showPassword); container.add(loginButton); container.add(resetButton); } public void addActionEvent() { loginButton.addActionListener(this); resetButton.addActionListener(this); showPassword.addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { //Coding Part of LOGIN button if (e.getSource() == loginButton) { String userText; String pwdText; userText = userTextField.getText(); pwdText = passwordField.getText(); if (userText.equalsIgnoreCase("mehtab") && pwdText.equalsIgnoreCase("12345")) { JOptionPane.showMessageDialog(this, "Login Successful"); } else { JOptionPane.showMessageDialog(this, "Invalid Username or Password"); } } //Coding Part of RESET button if (e.getSource() == resetButton) { userTextField.setText(""); passwordField.setText(""); } //Coding Part of showPassword JCheckBox if (e.getSource() == showPassword) { if (showPassword.isSelected()) { passwordField.setEchoChar((char) 0); } else { passwordField.setEchoChar('*'); } } } } public class Login { public static void main(String[] a) { LoginFrame frame = new LoginFrame(); frame.setTitle("Login Form"); frame.setVisible(true); frame.setBounds(10, 10, 350, 350); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); } } _________________________________________________________________

While the second code that has JDBC components is this: _________________________________________________________________

import java.sql.*;

public class TestStatement {

public static void main(String[] args) { try { // Load Driver String driver = "org.apache.derby.jdbc.ClientDriver"; Class.forName(driver); System.out.println("Loaded Driver: " + driver);

// Establish Connection String url = "jdbc:derby://localhost:1527/PersonDB"; String username = "app"; String password = "app"; Connection con = DriverManager.getConnection(url, username, password); System.out.println("Connected to: " + url);

// Create and Execute the Statement Statement stmt = con.createStatement(); String query = "SELECT * FROM PERSON_INFO ORDER BY name desc"; ResultSet rs = stmt.executeQuery(query); System.out.println("Executed Query: " + query);

// Retrieve the ResultSet System.out.println("Processing The Result Set: "); while (rs.next()) { System.out.println("Name: " + rs.getString("NAME").trim()); System.out.println("Age: " + rs.getString("AGE").trim()); System.out.println("Age: " + rs.getString("COUNTRY").trim()); System.out.println(); }

// Close the connection rs.close(); stmt.close(); con.close(); } catch (SQLException | ClassNotFoundException sqle) { sqle.printStackTrace(); } } } ____________________________________________________________________

SELECT from ACC_INFO X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books