Cute Dog drawing in the background + : Java with Netbeans ----------------------
ID: 3573247 • Letter: C
Question
Cute Dog drawing in the background + : Java with Netbeans -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Use Link to find out how to set up database in NetBeans
https://www.sis.pitt.edu/mbsclass/is2560/resources/UsingDerbyandDBMSinServlets.pdf
Applicant Manager Email First Name Last Name frankjones yahoo.com Bohn Smith Johnsmith@hotmail.com seagreen clevi.com Cynthia Green Wendy Gwarners.com Wendy Kowolski Add Edit Delete Create the code for the GUI based of the requirements Java codel syntax requirements for the GUI Create a table in the mma database described in chapter 19 to store the necessary data. To do that you can use the SQL script stored in the create Applicant table.sql file that's supplied. If this script isn't supplied, you can create your own SQL script Create a class named Applicant that stores data for the user's id, email address, first name, and last name. Create a class named ApplicantDB that contains the methods necessary to get an array list of Applicant objects, to get a Applicant object for the Applicant with the specified id, and to add, update, or delete the specified Applicant. Create a ApplicantManagerFrame class like the one shown above. This frame should display a table of Applicant data as well as the Add, Edit, and Delete buttons. This class should use the Applicant and ApplicantDB classes to work with the Applicant data. Create a ApplicantForm class that allows the user to add or edit Applicant data. How the GUI should function when code is done This application begins by displaying a table of Applicant data. If the user clicks the Add button, the application allows the user to add Applicant data to the table (and the underlying database) If the user selects a Applicant row and clicks the Edit button, the application all S the user to update the data for the selected Applicant row in the table (and the database) If the user selects a Applicant row and clicks the Delete button, the application deletes the selected Applicant row from the table (and the database)Explanation / Answer
Program:-
JAVA CODE FOR CREATING A TABLE APPLICATION.
import java.sql.*;
public class JDBCExample {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
System.out.println("Creating table in given database...");
stmt = conn.createStatement();
String sql = "CREATE TABLE APPLICATION " +
"(User_id not NULL, " +
" first_name VARCHAR(255), " +
" last_name VARCHAR(255), " +
" email VARCHAR(255), " +
" PRIMARY KEY ( User_id ))";
stmt.executeUpdate(sql);
System.out.println("Created table in given database...");
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
} }
System.out.println("Goodbye!");
}
}
Output:-
JAVA CODE FOR THE ADDITION OF DATA IN THE TABLE.
//STEP 1. Import required packages
import java.sql.*;
public class JDBCExample {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver")
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully//STEP 1. Import required packages
import java.sql.*;
public class JDBCExample {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{r
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
System.out.println("Inserting records into the table...");
stmt = conn.createSta String sql = "INSERT INTO Application" +
"VALUES (1000, 'Zara', 'khan', zaraali*gm.com)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration " +
"VALUES (1001, 'Manisha', 'sindhu', sindhumanisha*gm.com)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration " +
"VALUES (1002, 'Nikita ', 'gupta', nikkigupta*gm.com)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration " +
"VALUES(1003, 'Rubia', 'khanam', khanamrubiya*gm.com)";
stmt.executeUpdate(sql);
System.out.println("Inserted records into the table...");
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
}...");
Output:-
JAVA CODE FOR THE UPDATION OF DATA IN THE TABLE.
import java.sql.*;
public class JDBCExample {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "UPDATE Registration " +
"SET first-name = rahim WHERE id in (1001, 1002)";
stmt.executeUpdate(sql)
sql = "SELECT user_id, first_name, last_name, age FROM Application;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
int User_id = rs.getInt("id");
String first_name = rs.getString("first");
String last_name = rs.getString("last");
String email = rs.getString("email");
System.out.print("User_ID: " + id);
System.out.print(", First_name: " + first_name);
System.out.println(", Last_name: " + last_name);
System.out.print(", email: " + email);
}
rs.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
} System.out.println("Goodbye!");
}
}
Output:-
JAVA CODE FOR THE DELETION OF DATA IN THE TABLE.
import java.sql.*;
public class JDBCExample {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "DELETE FROM Application" +
"WHERE id = 1001";
stmt.executeUpdate(sql);
sql = "SELECT User_id, first_name, last_name, email FROM Application";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
int User_id = rs.getInt("id");
String first_name = rs.getString("first");
String last_name = rs.getString("last");
String email = rs.getString("email");
System.out.print("User_ID: " + id);
System.out.print(", First_name: " + first_name);
System.out.println(", Last_name: " + last_name);
System.out.print(", email: " + email
}
rs.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.