0% found this document useful (0 votes)
4 views22 pages

Java Trading Journal Database Code

The document contains Java source code for a Trading Journal Database System, which includes classes for database connection, menu creation, and table management. The application allows users to create, drop, and populate database tables, as well as query and view data through a graphical user interface. Key functionalities include executing SQL commands for managing user, trade, stock, and performance metrics data.
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)
4 views22 pages

Java Trading Journal Database Code

The document contains Java source code for a Trading Journal Database System, which includes classes for database connection, menu creation, and table management. The application allows users to create, drop, and populate database tables, as well as query and view data through a graphical user interface. Key functionalities include executing SQL commands for managing user, trade, stock, and performance metrics data.
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

Source Code Of Application

[Link]

import [Link].*;

public class DatabaseConnection {


public Connection connection = null;

public boolean createConnection() {


try {
[Link]("[Link]");
} catch (ClassNotFoundException e) {
[Link]();
return false;
}
try {
String dbURL =
"jdbc:oracle:thin:p59nguye/05013277@[Link]:ord";
connection = [Link](dbURL);

[Link]("Connected!");
return true;
} catch (SQLException e) {
[Link]();
return false;
}
}

public ResultSet executeQuery(String query) {


try {
Statement statement = [Link]();
return [Link](query);
} catch (SQLException e) {
[Link]();
return null;
}
}

public void executeAndDisplayQuery(String query) {


try (Statement statement = [Link]();
ResultSet resultSet = [Link](query)) {
ResultSetMetaData metaData = [Link]();
int columnCount = [Link]();

while ([Link]()) {
for (int i = 1; i <= columnCount; i++) {
String value = [Link](i);
[Link](value + " ");
}
[Link]();
}
} catch (SQLException e) {
[Link]();
}
}
}

[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class Menu {
private JFrame mainMenuFrame;
DatabaseConnection databaseConnection = new DatabaseConnection();
public static void main(String[] args) {
menuRunnable();
}
public static void menuRunnable() {
[Link](() -> {
try {
Menu menuWindow = new Menu();
[Link](true);
} catch (Exception e) {
[Link]();
}
});
}
public Menu() {
if ([Link]()) {
createMainMenuWindow();
}
}
private void createMainMenuWindow() {
mainMenuFrame = new JFrame();
[Link]("Trading Journal Database System");
[Link](100, 100, 480, 300);
[Link]().setLayout(null);
[Link](JFrame.EXIT_ON_CLOSE);
JLabel tradingSystemLabel = new JLabel("Trading Journal Database System");
[Link](new Font("Garamond", [Link], 24));
[Link](10, 0, 300, 50);
[Link]().add(tradingSystemLabel);
JButton dropTablesButton = new JButton("Drop Tables");
[Link](new Color(139, 0, 0));
[Link](new Font("Garamond", [Link], 16));
[Link](10, 60, 140, 24);
[Link]().add(dropTablesButton);
JButton createTablesButton = new JButton("Create Tables");
[Link](new Color(0, 128, 0));
[Link](new Font("Garamond", [Link], 16));
[Link](160, 60, 140, 24);
[Link]().add(createTablesButton);
JButton populateTablesButton = new JButton("Insert Data");
[Link](new Color(0, 191, 255));
[Link](new Font("Garamond", [Link], 16));
[Link](310, 60, 140, 24);
[Link]().add(populateTablesButton);
[Link](
mainMenuFrame, databaseConnection, dropTablesButton);
[Link](
mainMenuFrame, databaseConnection, createTablesButton);
[Link](
mainMenuFrame, databaseConnection, populateTablesButton);
JButton viewTablesButton = new JButton("View");
[Link](new Color(0, 0, 0));
[Link](new Font("Garamond", [Link], 18));
[Link](10, 100, 140, 140);
[Link]().add(viewTablesButton);
JButton queryTablesButton = new JButton("Query");
[Link](new Color(0, 0, 0));
[Link](new Font("Garamond", [Link], 18));
[Link](160, 100, 140, 140);
[Link]().add(queryTablesButton);
JButton updateTablesButton = new JButton("Edit");
[Link](new Color(0, 0, 0));
[Link](new Font("Garamond", [Link], 18));
[Link](310, 100, 140, 140);
[Link]().add(updateTablesButton);
[Link](actionEvent -> {
ViewTables viewTable = new ViewTables();
[Link]();
[Link](false);
});
[Link](actionEvent -> {
QueryTables queryTable = new QueryTables();
[Link]();
[Link](false);
});
[Link](actionEvent -> {
UpdateTables updateTable = new UpdateTables();
[Link]();
[Link](false);
});
JButton backButton = new JButton("<");
[Link](new Font("Garamond", [Link], 14));
[Link](400, 15, 50, 20);
[Link]().add(backButton);
[Link](actionEvent -> {
Login login = new Login();
[Link]();
[Link]();
});
}
public static void executeButtonActionEvent(JButton tableButton,
DatabaseConnection databaseConnection, String query) {
[Link](actionEvent -> {
try {
ResultSet queryResult = [Link](query);
JTable queryResultTable = new JTable(buildTableModel(queryResult));
[Link](null, new JScrollPane(queryResultTable));
} catch (SQLException e) {
[Link]();
}
});
}
public static DefaultTableModel buildTableModel(ResultSet queryResult)
throws SQLException {
ResultSetMetaData queryMetaData = [Link]();
int columnCount = [Link]();
Vector<String> columnNames = new Vector<>();
Vector<Vector<Object>> queryDataVector = new Vector<>();
for (int columnNumber = 1; columnNumber <= columnCount; columnNumber++) {
[Link]([Link](columnNumber));
}
while ([Link]()) {
Vector<Object> tempDataVector = new Vector<>();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
[Link]([Link](columnIndex));
}
[Link](tempDataVector);
}
return new DefaultTableModel(queryDataVector, columnNames);
}
}

[Link]
import [Link].*;

public class DropTables {


public static void executeDropQueries(JFrame mainMenuFrame,
DatabaseConnection databaseConnection, JButton dropTablesButton) {
[Link](actionEvent -> {
// Drop the tables related to your database
[Link](
"DROP TABLE Journal_Entry CASCADE CONSTRAINTS PURGE");
[Link](
"DROP TABLE Performance_Metrics CASCADE CONSTRAINTS PURGE");
[Link](
"DROP TABLE Stock CASCADE CONSTRAINTS PURGE");
[Link](
"DROP TABLE Trade CASCADE CONSTRAINTS PURGE");
[Link](
"DROP TABLE User CASCADE CONSTRAINTS PURGE");

// Commit the transaction


[Link]("COMMIT");

// Show a confirmation message


[Link](
mainMenuFrame, "All Specified Tables Dropped");
});
}
}

[Link]
import [Link].*;

public class CreateTables {


public static void executeCreateQueries(JFrame mainMenuFrame,
DatabaseConnection databaseConnection, JButton createTablesButton) {
[Link](actionEvent -> {
// Create User table
[Link]("CREATE TABLE User ("
+ "User_ID NUMBER PRIMARY KEY, "
+ "First_Name VARCHAR2(50) NOT NULL, "
+ "Last_Name VARCHAR2(50) NOT NULL, "
+ "Email VARCHAR2(50) NOT NULL UNIQUE, "
+ "Encrypted_Password VARCHAR2(50) NOT NULL)");

// Create Trade table


[Link]("CREATE TABLE Trade ("
+ "Trade_ID NUMBER PRIMARY KEY, "
+ "User_ID NUMBER NOT NULL REFERENCES User(User_ID), "
+ "Stock_Symbol VARCHAR2(10) NOT NULL, "
+ "Entry_Date DATE NOT NULL, "
+ "Exit_Date DATE, "
+ "Entry_Price NUMBER NOT NULL, "
+ "Exit_Price NUMBER, "
+ "Position VARCHAR2(10) NOT NULL, "
+ "Volume NUMBER NOT NULL, "
+ "Commission_Fee NUMBER NOT NULL)");

// Create Stock table


[Link]("CREATE TABLE Stock ("
+ "Stock_Symbol VARCHAR2(10) PRIMARY KEY, "
+ "Company_Name VARCHAR2(50) NOT NULL, "
+ "Sector VARCHAR2(50) NOT NULL)");

// Create Performance Metrics table


[Link]("CREATE TABLE Performance_Metrics ("
+ "Metrics_ID NUMBER PRIMARY KEY, "
+ "User_ID NUMBER NOT NULL REFERENCES User(User_ID), "
+ "ROI NUMBER NOT NULL, "
+ "Average_Profit_Loss NUMBER NOT NULL, "
+ "Win_Loss_Ratio NUMBER NOT NULL)");

// Create Journal Entry table


[Link]("CREATE TABLE Journal_Entry ("
+ "Journal_ID NUMBER PRIMARY KEY, "
+ "Trade_ID NUMBER NOT NULL REFERENCES Trade(Trade_ID), "
+ "Notes VARCHAR2(255), "
+ "Emotions VARCHAR2(50), "
+ "Strategy_Tag VARCHAR2(50), "
+ "Attachments BLOB)");

// Show a confirmation message


[Link](mainMenuFrame, "All Tables Created!");
});
}
}

[Link]
import [Link].*;

public class PopulateTables {


public static void executePopulateDataQueries(JFrame mainMenuFrame,
DatabaseConnection databaseConnection, JButton populateTablesButton) {
[Link](
actionEvent -> {
// Insert data into User table
String[] userInserts = {
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (1, 'John', 'Doe', '[Link]@[Link]', 'password1')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (2, 'Jane', 'Doe', '[Link]@[Link]', 'password2')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (3, 'Alice', 'Brown', '[Link]@[Link]', 'password3')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (4, 'Bob', 'Smith', '[Link]@[Link]', 'password4')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (5, 'Charlie', 'Johnson', '[Link]@[Link]',
'password5')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (6, 'Dave', 'Williams', '[Link]@[Link]',
'password6')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (7, 'Eve', 'Jones', '[Link]@[Link]', 'password7')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (8, 'Frank', 'Garcia', '[Link]@[Link]', 'password8')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (9, 'Grace', 'Martinez', '[Link]@[Link]',
'password9')",
"INSERT INTO User(User_ID, First_Name, Last_Name, Email,
Encrypted_Password) VALUES (10, 'Emily', 'Smith', '[Link]@[Link]',
'password10')"};
for (String insertQuery : userInserts) {
[Link](insertQuery);
}

// Insert data into Stock table


String[] stockInserts = {
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('AAPL',
'Apple Inc.', 'Technology')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES
('GOOGL', 'Google', 'Technology')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('AMZN',
'Amazon', 'Retail')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('MSFT',
'Microsoft', 'Technology')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('TSLA',
'Tesla', 'Automotive')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('FB',
'Facebook', 'Technology')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('JPM',
'JPMorgan Chase', 'Finance')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('V',
'Visa', 'Finance')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('WMT',
'Walmart', 'Retail')",
"INSERT INTO Stock(Stock_Symbol, Company_Name, Sector) VALUES ('PG',
'Procter & Gamble', 'Consumer Goods')"};
for (String insertQuery : stockInserts) {
[Link](insertQuery);
}

// Insert data into Trade table


String
[] tradeInserts =
{"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (1, 1,
'AAPL', TO_DATE('2023-01-01', 'YYYY-MM-DD'), TO_DATE('2023-01-10', 'YYYY-MM-
DD'), 150, 160, 'Long', 10, 5)",
"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (2, 1,
'GOOGL', TO_DATE('2023-01-02', 'YYYY-MM-DD'), TO_DATE('2023-01-11', 'YYYY-
MM-DD'), 2000, 2100, 'Long', 5, 10)",
"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (3, 1,
'AMZN', TO_DATE('2023-01-03', 'YYYY-MM-DD'), TO_DATE('2023-01-12', 'YYYY-MM-
DD'), 1800, 1850, 'Short', 8, 6)",
"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (4, 2,
'MSFT', TO_DATE('2023-01-04', 'YYYY-MM-DD'), TO_DATE('2023-01-13', 'YYYY-MM-
DD'), 200, 205, 'Long', 12, 4)",
"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (5, 3,
'TSLA', TO_DATE('2023-01-05', 'YYYY-MM-DD'), TO_DATE('2023-01-14', 'YYYY-MM-
DD'), 600, 650, 'Short', 15, 7)", "INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol,
Entry_Date, Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee)
VALUES (6, 3, 'FB', TO_DATE('2023-01-06', 'YYYY-MM-DD'), TO_DATE('2023-01-15',
'YYYY-MM-DD'), 300, 290, 'Long', 20, 8)", "INSERT INTO Trade(Trade_ID, User_ID,
Stock_Symbol, Entry_Date, Exit_Date, Entry_Price, Exit_Price, Position, Volume,
Commission_Fee) VALUES (7, 4, 'JPM', TO_DATE('2023-01-07', 'YYYY-MM-DD'),
TO_DATE('2023-01-16', 'YYYY-MM-DD'), 100, 105, 'Short', 30, 9)", "INSERT INTO
Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date, Exit_Date, Entry_Price, Exit_Price,
Position, Volume, Commission_Fee) VALUES (8, 5, 'V', TO_DATE('2023-01-08', 'YYYY-
MM-DD'), TO_DATE('2023-01-17', 'YYYY-MM-DD'), 180, 190, 'Long', 25, 3)", "INSERT
INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date, Exit_Date, Entry_Price,
Exit_Price, Position, Volume, Commission_Fee) VALUES (9, 6, 'WMT', TO_DATE('2023-
01-09', 'YYYY-MM-DD'), TO_DATE('2023-01-18', 'YYYY-MM-DD'), 120, 130, 'Short', 22,
2)",
"INSERT INTO Trade(Trade_ID, User_ID, Stock_Symbol, Entry_Date,
Exit_Date, Entry_Price, Exit_Price, Position, Volume, Commission_Fee) VALUES (10, 2,
'PG', TO_DATE('2023-01-10', 'YYYY-MM-DD'), TO_DATE('2023-01-19', 'YYYY-MM-
DD'), 90, 95, 'Long', 33, 1)"};

for (String insertQuery : tradeInserts) {


[Link](insertQuery);
}

// Insert data into Performance Metrics table


String[] performanceMetricsInserts = {
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (1, 1, 0.1, 50, 0.8)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (2, 1, 0.2, 60, 0.7)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (3, 2, 0.3, 70, 0.6)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (4, 2, 0.4, 80, 0.5)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (5, 3, 0.5, 90, 0.9)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (6, 3, 0.6, 100, 0.4)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (7, 4, 0.7, 110, 0.3)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (8, 5, 0.8, 120, 0.2)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (9, 6, 0.9, 130, 0.1)",
"INSERT INTO Performance_Metrics(Metrics_ID, User_ID, ROI,
Average_Profit_Loss, Win_Loss_Ratio) VALUES (10, 2, 0.5, 100, 0.9)"};
for (String insertQuery : performanceMetricsInserts) {
[Link](insertQuery);
}

// Insert data into Journal Entry table


String[] journalEntryInserts = {
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (1, 1, 'Good Trade', 'Calm', 'Breakout', '[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (2, 2, 'Bad Trade', 'Nervous', 'Mean Reversion',
'[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (3, 3, 'Average Trade', 'Neutral', 'Momentum',
'[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (4, 4, 'Excellent Trade', 'Excited', 'Breakout',
'[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (5, 5, 'Poor Trade', 'Anxious', 'Scalping', '[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (6, 6, 'Decent Trade', 'Content', 'Trend Following',
'[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (7, 7, 'Good Trade', 'Calm', 'Breakout', '[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (8, 8, 'Bad Trade', 'Frustrated', 'Reversal', '[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (9, 9, 'Okay Trade', 'Indifferent', 'Range Trading',
'[Link]')",
"INSERT INTO Journal_Entry(Journal_ID, Trade_ID, Notes, Emotions,
Strategy_Tag, Attachments) VALUES (10, 10, 'Average Trade', 'Neutral', 'Momentum',
'[Link]')"};

for (String insertQuery : journalEntryInserts) {


[Link](insertQuery);
}

// Show a confirmation message


[Link](mainMenuFrame, "All Tables Populated!");
});
}
}
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ViewTables {


private JFrame viewTableFrame;
DatabaseConnection databaseConnection = new DatabaseConnection();
private static List<String> queryNames = new ArrayList<>();
private static List<String> queryCommands = new ArrayList<>();

public static void viewTableRunnable() {


[Link](() -> {
try {
ViewTables viewTableWindow = new ViewTables();
[Link](true);
} catch (Exception e) {
[Link]();
}
});
}

public ViewTables() {
if ([Link]()) {
createViewTableWindow();
}
}

private void createViewTableWindow() {


viewTableFrame = new JFrame();
[Link]("View Tables");
[Link](100, 100, 360, 500);
[Link]().setLayout(null);
[Link](JFrame.EXIT_ON_CLOSE);

JLabel tableLabel = new JLabel("Trading System Tables");


[Link](new Font("Garamond", [Link], 24));
[Link](10, 0, 340, 50);
[Link]().add(tableLabel);

[Link]("User");
[Link]("Trade");
[Link]("Stock");
[Link]("Performance Metrics");
[Link]("Journal Entry");

[Link]("SELECT * FROM USER");


[Link]("SELECT * FROM TRADE");
[Link]("SELECT * FROM STOCK");
[Link]("SELECT * FROM PERFORMANCE_METRICS");
[Link]("SELECT * FROM JOURNAL_ENTRY");

int yPosition = 50;


for (int i = 0; i < [Link](); i++) {
JButton tableButton = new JButton([Link](i));
[Link](new Font("Garamond", [Link], 18));
[Link](50, yPosition, 240, 30);
[Link]().add(tableButton);
yPosition += 40;
int finalI = i;
[Link](actionEvent -> {
[Link]([Link](finalI));
});
}

JButton backButton = new JButton("<");


[Link](new Font("Garamond", [Link], 14));
[Link](280, 15, 50, 20);
[Link]().add(backButton);
[Link](actionEvent -> {
Menu menu = new Menu();
[Link]();
[Link]();
});
}
}

[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;

public class QueryTables {


private JFrame queryTablesFrame;
private DatabaseConnection databaseConnection = new DatabaseConnection();
private static List<String> queryNames = new ArrayList<>();
private static List<String> queryCommands = new ArrayList<>();

public static void queryTableRunnable() {


[Link](() -> {
try {
QueryTables queryTablesWindow = new QueryTables();
[Link](true);
} catch (Exception e) {
[Link]();
}
});
}

public QueryTables() {
if ([Link]()) {
createQueryTablesWindow();
}
}

private void createQueryTablesWindow() {


queryTablesFrame = new JFrame();
[Link]("Query Tables");
[Link](100, 100, 480, 550);
[Link]().setLayout(null);
[Link](JFrame.EXIT_ON_CLOSE);

JLabel queryLabel = new JLabel("Trading System Queries");


[Link](new Font("Garamond", [Link], 24));
[Link](10, 0, 460, 50);
[Link]().add(queryLabel);

// Example queries for the trading system


[Link]("1. List of All Users");
[Link]("2. Recent Trades");
[Link]("3. Stocks in Technology Sector");
[Link]("4. User Performance Metrics");
[Link]("5. Journal Entries for Trade ID");

[Link]("SELECT * FROM USER");


[Link]("SELECT * FROM TRADE ORDER BY Entry_Date DESC");
[Link]("SELECT * FROM STOCK WHERE Sector = 'Technology'");
[Link]("SELECT * FROM PERFORMANCE_METRICS");
[Link]("SELECT * FROM JOURNAL_ENTRY WHERE Trade_ID = 1");

int yPos = 60;


for (int i = 0; i < [Link](); i++) {
JButton queryButton = new JButton([Link](i));
[Link](new Font("Garamond", [Link], 14));
[Link](30, yPos, 400, 30);
[Link]().add(queryButton);
int finalI = i;
[Link](actionEvent -> {
[Link]([Link](finalI));
});
yPos += 40;
}

JButton backButton = new JButton("<");


[Link](new Font("Garamond", [Link], 12));
[Link](400, 15, 50, 20);
[Link]().add(backButton);
[Link](actionEvent -> {
Menu menu = new Menu();
[Link]();
[Link]();
});
}
}

[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class UpdateTables {


private JFrame updateTableFrame;
DatabaseConnection databaseConnection = new DatabaseConnection();
public void updateTablesRunnable() {
[Link](() -> {
try {
UpdateTables updateTableWindow = new UpdateTables();
[Link](true);
} catch (Exception e) {
[Link]();
}
});
}

public UpdateTables() {
if ([Link]()) {
createUpdateTablesWindow();
}
}

private void createUpdateTablesWindow() {


updateTableFrame = new JFrame();
[Link](100, 100, 480, 320);
[Link]().setLayout(null);
[Link](JFrame.EXIT_ON_CLOSE);

JLabel editLabel = new JLabel("Edit Trading System Tables");


[Link](new Font("Garamond", [Link], 24));
[Link](10, 0, 460, 50);
[Link]().add(editLabel);

createUpdateSection();
createInsertSection();
createRemoveSection();

JButton backButton = new JButton("<");


[Link](new Font("Garamond", [Link], 12));
[Link](400, 15, 50, 20);
[Link]().add(backButton);
[Link](actionEvent -> {
Menu menu = new Menu();
[Link]();
[Link]();
});
}

private void createUpdateSection() {


// Update Section
JButton updateButton = new JButton("Update");
[Link](new Font("Garamond", [Link], 16));
[Link](20, 60, 100, 30);
[Link]().add(updateButton);
JTextField updateTextField = new JTextField("UPDATE table-name");
[Link](140, 60, 300, 20);
[Link]().add(updateTextField);
JTextField setTextField =
new JTextField("SET column-name = value, column-name = value, ...");
[Link](140, 80, 300, 20);
[Link]().add(setTextField);
JTextField whereTextField = new JTextField("WHERE condition");
[Link](140, 100, 300, 20);
[Link]().add(whereTextField);
[Link](actionEvent
-> executeUpdate(updateTextField, setTextField, whereTextField));
}

private void createInsertSection() {


// Insert Section
JButton insertButton = new JButton("Insert");
[Link](new Font("Garamond", [Link], 16));
[Link](20, 140, 100, 30);
[Link]().add(insertButton);
JTextField insertIntoTextField = new JTextField("INSERT INTO table-name");
[Link](140, 140, 300, 20);
[Link](500);
[Link]().add(insertIntoTextField);
JTextField insertAttributeNamesTextField = new JTextField("(column-names)");
[Link](140, 160, 300, 20);
[Link](500);
[Link]().add(insertAttributeNamesTextField);
JTextField insertValuesTextField = new JTextField("VALUES (values)");
[Link](140, 180, 300, 20);
[Link](500);
[Link]().add(insertValuesTextField);
[Link](actionEvent
-> executeInsert(insertIntoTextField, insertAttributeNamesTextField,
insertValuesTextField));
}

private void createRemoveSection() {


// Remove Section
JButton removeButton = new JButton("Remove");
[Link](new Font("Garamond", [Link], 16));
[Link](20, 220, 100, 30);
[Link]().add(removeButton);
JTextField deleteTableTextField = new JTextField("DELETE table-name");
[Link](140, 220, 300, 20);
[Link](500);
[Link]().add(deleteTableTextField);
JTextField deleteConditionTextField = new JTextField("WHERE condition");
[Link](140, 240, 300, 20);
[Link](500);
[Link]().add(deleteConditionTextField);
[Link](actionEvent
-> executeRemove(deleteTableTextField, deleteConditionTextField));
}

private void executeUpdate(JTextField updateTextField,


JTextField setTextField, JTextField whereTextField) {
String updateTextString = [Link]();
String setTextString = [Link]();
String whereTextString = [Link]();
String queryStatement =
updateTextString + " " + setTextString + " " + whereTextString;
[Link](queryStatement);
[Link](updateTableFrame, "Updated!");
}

private void executeInsert(JTextField insertIntoTextField,


JTextField insertAttributeNamesTextField,
JTextField insertValuesTextField) {
String insertIntoString = [Link]();
String insertAttributeNamesString = [Link]();
String insertValuesString = [Link]();
String queryStatement = insertIntoString + " " + insertAttributeNamesString
+ " " + insertValuesString;
[Link](queryStatement);
[Link](updateTableFrame, "Inserted!");
}

private void executeRemove(


JTextField deleteTableTextField, JTextField deleteConditionTextField) {
String deleteTableString = [Link]();
String deleteConditionString = [Link]();
String queryStatement = deleteTableString + " " + deleteConditionString;
[Link](queryStatement);
[Link](updateTableFrame, "Removed!");
}
}

You might also like