Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do the following in Java and SQL. Will Rate your answer afterwards! 1. Im

ID: 3902911 • Letter: P

Question

Please do the following in Java and SQL. Will Rate your answer afterwards!

1. Implement a button called “Initialize Database”. When a user clicks it, all necessary tables will be created (or recreated) automatically, with each table be populated with at least 10 tuples so that each query below will return some results. All students should use the database name “sampledb”, username “john”, and password “pass1234”.

2. Implement a user registration and login interface so that only a registered user can login into the system.

3. Create the functionality to assign three reviewers to a paper.

Explanation / Answer

//import package

import java.sql.*;

publiic class JDBCTuple {

static final String JDBC_DRIVER= "com.mysql.jdbc.Driver";

static final String DB_URL="jdbc:mysql://localhost/STUDENTS";

static final String USER="john";

static final String PASS="pass1234";

public static void main (String args[]) {

Connection conn=null;

Statement stmt=null;

try{ // register JDBC driver

Class.forName("com.mysql.jdbc.Driver");

//Open a connection

System.out.println("connecting to a selected database....");

Conn= DriverManager.getConnection(DB_URL,USER, PASS);

System.out.println("connection created successfully");

//Executing query

System.out.println("Creating table in database");

stmt=conn.createStatement();

String sql="create table registration"+"(id INTEGER not null,"+"first VARCHAR(255),"+"last VARCHAR(255),'+"age INTEGER,"+"PRIMARY KEY(I'd))";

stmt.executeUpdate(sql);

System.out.println("creating table in dB");

}

catch(SQL Exception se)

{} // Do nothing

try

{//Handle errors for JDBC

se.printStackTrace();}

finally

{ //Final block to close resources

try{if(stmt!=null) conn.close();}

catch(SQLException se)

{ se.printStackTrace();}

}

System.out.println("goodbye");

}

}