servletworkbench queries
servletworkbench queries
Here is the SQL code to create the necessary tables for your servlet-based expense tracker, following the
format you provided. The schema name and table name are based on the information from your servlet code:
SQL Queries
sql
Copy code
CREATE DATABASE IF NOT EXISTS expensetracker;
sql
Copy code
CREATE TABLE `expensetracker`.`expenses` (
`expense_id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`amount` DOUBLE NOT NULL,
`category` VARCHAR(255) NOT NULL,
`date` DATE NOT NULL,
PRIMARY KEY (`expense_id`)
);
Explanation of Columns:
This table structure corresponds to the SQL operations defined in the servlet's methods for adding an
expense and viewing expenses by category.
Notes:
If you also need a users table (for storing user data), you can create it similarly.
Make sure the database is configured correctly and your
jdbc:mysql://localhost:3306/expensetracker connection works with the provided credentials
(root as the username and tiger as the password).
2)servletproject2
Here are the SQL queries to create the necessary tables for your servlet-based bank system, following the
format you provided. The schema name is bank and the table names are based on the servlet operations such
as creating accounts, deposits, withdrawals, and transactions.
SQL Queries
sql
Copy code
CREATE TABLE `bank`.`accounts` (
`account_id` INT NOT NULL AUTO_INCREMENT,
`user_name` VARCHAR(255) NOT NULL,
`balance` DOUBLE NOT NULL DEFAULT 0,
PRIMARY KEY (`account_id`)
);
sql
Copy code
CREATE TABLE `bank`.`transactions` (
`transaction_id` INT NOT NULL AUTO_INCREMENT,
`account_id` INT NOT NULL,
`type` ENUM('Deposit', 'Withdrawal') NOT NULL,
`amount` DOUBLE NOT NULL,
`transaction_date` DATE NOT NULL,
PRIMARY KEY (`transaction_id`),
FOREIGN KEY (`account_id`) REFERENCES `accounts`(`account_id`)
);
Notes:
Make sure your database user root has access to the bank schema and the database password is
correct (tiger).
The transactions are recorded using account_id, ensuring that each deposit/withdrawal is tied to an
account.
3)servletproject3
Here are the SQL queries to create the necessary tables for your servlet-based employee management
system, following the same format as the previous requests. The schema name is employee_management,
and the relevant table is employees.
SQL Queries
sql
Copy code
CREATE DATABASE IF NOT EXISTS employee_management;
sql
Copy code
CREATE TABLE `employee_management`.`employees` (
`employee_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`department_id` INT NOT NULL,
`salary` DOUBLE NOT NULL,
PRIMARY KEY (`employee_id`)
);
Make sure the employee_management database exists, and ensure the user root has appropriate access to it,
with the correct password (tiger).
4)servletproject4
Here are the SQL queries to create the necessary tables for your servlet-based library management system,
following the same format as the previous requests. The schema name is library, and the relevant tables
are books, borrowers, and lending.
SQL Queries
sql
Copy code
CREATE DATABASE IF NOT EXISTS library;
sql
Copy code
CREATE TABLE `library`.`books` (
`book_id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NOT NULL,
`author` VARCHAR(255) NOT NULL,
`publisher` VARCHAR(255),
`quantity` INT NOT NULL,
PRIMARY KEY (`book_id`)
);
sql
Copy code
CREATE TABLE `library`.`borrowers` (
`borrower_id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255),
`phone` VARCHAR(15),
PRIMARY KEY (`borrower_id`)
);
sql
Copy code
CREATE TABLE `library`.`lending` (
`lending_id` INT NOT NULL AUTO_INCREMENT,
`book_id` INT NOT NULL,
`borrower_id` INT NOT NULL,
`issue_date` DATE NOT NULL,
`return_date` DATE,
PRIMARY KEY (`lending_id`),
FOREIGN KEY (`book_id`) REFERENCES `books` (`book_id`),
FOREIGN KEY (`borrower_id`) REFERENCES `borrowers` (`borrower_id`)
);
Explanation of Tables:
1. books: Stores information about books in the library (ID, title, author, publisher, and quantity
available).
2. borrowers: Stores information about borrowers (ID, name, email, phone).
3. lending: Records the transactions of borrowing books (ID, book ID, borrower ID, issue date, and
return date).
Ensure the library database exists and the root user has the appropriate permissions to access and modify
it.