Question: JAVA HELP. Please do not answer randomly unless you know what you are doing. Ill give thumbs up for you. Thanks. COMPLETE THE MAIN METHOD

JAVA HELP. Please do not answer randomly unless you know what you are doing. Ill give thumbs up for you. Thanks. COMPLETE THE MAIN METHOD only. Make us of SQL, SimpleDataSource class. Additionally, database.properties, derby.jar is required. The derby can be download here: https://db.apache.org/derby/

For database.properties

jdbc.url=jdbc:derby:BigJavaDB;create=true

# With other databases, you may need to add entries such as these

# jdbc.username=admin

# jdbc.password=secret

# jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver

********************************************************************

THIS MAIN METHOD MUST BE completed and must be fully functional to execute,

MAIN METHOD:

------------------------------------------------------------------------------

public class Employee{

public static void main(String[] args)

{

try

{

//use methods for system tables

SQL.Initialize();

SQL.defaultSet();

SQL.rowsTest();

SQL.ComAlterRow("WeekHours","hoursWorked=200,weekNum=1","employeeID=0");

SQL.ComQuery(" * "," WeekHours "," employeeID=0 ");

//use methods for custom user tables

SQL.AddTable();

//Dept

//deptID INT

//deptName varchar(20)

//done

SQL.InsertRow();

//Dept

// 0, 'Finance'

SQL.AlterRow();

//Dept

//deptName='Account'

//deptID=0

SQL.RemoveRow();

//Dept

//deptID=0

ResultSet rs=SQL.useQuery();

// deptname

// Dept

// deptID=0

SQL.PrintResultSet(rs);

}

catch(SQLException e)

{

System.out.println(e)

}

}

*******************************************************************************

SQL CLASS:

-----------------

import java.io.IOException;

import java.sql.*;

import java.util.*;

public class SQL {// runs the SQL codes for other class use.

//Initializes the database.

public static void Initialize() throws IOException, SQLException,

ClassNotFoundException {

String start = "database.properties";

SimpleDataSource.init(start);

}

public static void defaultSet () throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

comAddTable("Employees", "(employeeID INT, Name varchar(40), SSN INT, maritalStatus varchar(20), hourlyPayRate double)");

comAddTable("WeekHours", "(employeeID INT, hoursWorked INT, weekNum INT)");

comAddTable("EmployeeTotals", "(employeeID INT, totalGrossPay double, totalFedralTaxes double, totalFICATaxes double, totalMedicareTaxes double, totalStateTaxes double, totalNetPay double)");

comAddTable("Checks", "(checkNum int, employeeID INT, ammount double, dateIssued varchar(10), grossPay double, deductFederal double, FICA double, Medicare double, stateTaxes double)");

}

}

public static void rowsTest() throws SQLException{

ComInsertRow("Employees", "(0, 'testName', 000000000, 'no', 7.25)");

ComInsertRow("WeekHours", "(0, 100, 0)");

ComInsertRow("EmployeeTotals", "(0, 500.00, 10.00, 15.00, 5.00, 12.00, 542.00)");

ComInsertRow("Checks", "(0, 0, 500.00, '12/4/17', 500.00, 10.00, 15.00, 5.00, 12.00)");

}

//Runs SQL run generated completly by the user. in-progress.

public static void comLine() throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

Scanner in = new Scanner (System.in);

System.out.println("Please type your full SQL line, to print a query type PRINT, to exit type DONE.");

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to add a table via human input.

public static void AddTable () throws SQLException {

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

Scanner in = new Scanner (System.in);

System.out.println("Name of the Table: (no spaces)");

String tableName = in.next();

System.out.println("Proper Syntax is (CollumnName DateType), please type done to quit. or datatype for list of datatypes.");

String input;

ArrayList sections = new ArrayList();

boolean cont = true;

while (cont = true){

input = in.nextLine();

if (input.equalsIgnoreCase("done")){

cont = false;

}

else if(input.equalsIgnoreCase("datatype")) {

System.out.println("data types include:");

System.out.println("INT");

System.out.println("FLOAT");

System.out.println("REAL");

System.out.println("DOUBLE");

System.out.println("DECIMAL(totalDigits, digitsAfterDecimal)");

System.out.println("BOOLEAN");

System.out.println("VARCHAR(length) this is variable length string.");

System.out.println("CHAR(length) fixed length string.");

}

else {

sections.add(input);

}

String connect= sections.get(0);

for (int i=1; i

connect = connect + ", " + sections.get(i);

}

stat.execute("CREATE TABLE "+tableName+ " ( "+ connect+ " )");

}

in.close();

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to add a table via computer input.

public static void comAddTable(String tableName, String columns) throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

stat.execute("CREATE TABLE "+tableName+ " "+ columns);

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to add a row to a table.

public static void InsertRow() throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

Scanner in = new Scanner (System.in);

System.out.println("Table to add row: (tableName or tableName (columnName1, columnName2, ....)");

String table = in.nextLine();

System.out.println("Values listed: (Values listed in table order, or columnName given order. ");

String values = in.nextLine();

stat.execute("INSERT INTO " + table + " VALUES ( " + values +" )");

in.close();

}catch (SQLException e) {

e.printStackTrace();

}

}

public static void ComInsertRow(String table, String values) throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

stat.execute("INSERT INTO " + table + " VALUES " + values);

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to let a human to make changes to SQL tables.

public static void AlterRow() throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{// UPDATE SET WHERE

Statement stat = conn.createStatement();

Scanner in = new Scanner (System.in);

System.out.println("Table to be updated: (one word)");

String table = in.next();

System.out.println("Updated information: (collumnName = 'data' [if more data separate with ,]");

in.nextLine();

String set = in.nextLine();

System.out.println("Conditions: (collumnName = 'data' [if multiple conditions use AND OR NOT to connect]");

String conditions = in.nextLine();

stat.execute("UPDATE "+ table + " SET "+ set + " WHERE " + conditions);

in.close();

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to let a computer make changes to SQL tables.

public static void ComAlterRow(String table, String set, String conditions) throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

stat.execute("UPDATE "+ table + " SET "+ set + " WHERE " + conditions );

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to Remove a Row.

public static void RemoveRow() throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

Scanner in = new Scanner (System.in);

System.out.println("Table to remove row from: ");

String table = in.next();

System.out.println("Conditions to remove rows: ");

in.nextLine();

String conditions = in.nextLine();

stat.execute("DELETE FROM " + table + " WHERE " + conditions);

in.close();

}catch (SQLException e) {

e.printStackTrace();

}

}

//Runs SQL to let a human generate a ResultSet.

public static void UseQuery() throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

ResultSet result;

Scanner in = new Scanner(System.in);

System.out.println("please input SELECT input");

String Select = in.nextLine();

System.out.println("please input FROM input");

String From = in.nextLine();

System.out.println("please input WHERE input");

String Where = in.nextLine();

result = stat.executeQuery("SELECT "+Select+" FROM "+From+" WHERE "+Where);

ResultSetMetaData meta = result.getMetaData();

int columnsNumber = meta.getColumnCount();

while (result.next()) {

for (int i = 1; i <= columnsNumber; i++) {

if (i > 1) System.out.print(", ");

String columnValue = result.getString(i);

System.out.print(columnValue + " " + meta.getColumnName(i));

}

System.out.println("");

}

in.close();

}

}

//Runs SQL to let a computer generate a ResultSet.

public static void ComQuery(String Select, String From, String Where) throws SQLException{

try (Connection conn = SimpleDataSource.getConnection())

{

Statement stat = conn.createStatement();

ResultSet result = stat.executeQuery("SELECT "+Select+" FROM "+From+" WHERE "+Where);

ResultSetMetaData meta = result.getMetaData();

int columnsNumber = meta.getColumnCount();

while (result.next()) {

for (int i = 1; i <= columnsNumber; i++) {

if (i > 1) System.out.print(", ");

String columnValue = result.getString(i);

System.out.print(columnValue + " " + meta.getColumnName(i));

}

System.out.println("");

}

}

}

}

*******************************

SimpleDataSource class:

--------------------------------

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

/**

A simple data source for getting database connections.

*/

public class SimpleDataSource

{

private static String url;

private static String username;

private static String password;

/**

Initializes the data source.

@param fileName the name of the property file that

contains the database driver, URL, username, and password

*/

public static void init(String fileName) throws IOException,

ClassNotFoundException

{

//complete this method

}

/**

Gets a connection to the database.

@return the database connection

*/

public static Connection getConnection() throws SQLException

{

//complete this method

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!