Computer 9 Javascript Display - Java
Computer 9 Javascript Display - Java
*;
Import java.sql.*;
String lastname = null, firstname = null, middleinit = null, address = null, landline = null;
String cellphone = null, email = null, bday =null, comments = null, favorite dish = null;
Date birthday = new Date (0000-00-00);
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
Try {
System.out.println(“You have chosen to add a record”);
Sysytem.out.println(“Please enter your friend’s basic info.”);
System.out.print(“First name : “);
firstname = br.readLine();
System.out.print(“Middle initial : “);
middlinit = br.readLine();
System.out.print(“Lastname : “);
lastname = br.readLine();
String qry = “SELECT * from profile where firstname=? and mi=? and lastname=?’;
ps.setString(1,firstname);
ps.setString(2,middleinit);
ps.setString(3,lastname);
ps.excecuteQuery();
ResultSet resset = ps.getResultSet();
If (resset).next()) {
System.out.println(“\nOops, that record is already in the database! “);
System.out.println(“Sorry, you can’t add an existing record”);
System.exit(0);
}
else {
System.out.print(“Address : “);
address = br.readLine();
System.out.print(“Land line : “);
landline = br.readLine();
System.out.print(“Cellphone : “);
cellphone = br.readLine();
System.out.print(“Email : “);
email = br.readLine();
System.out.print(“Bday (yyyy-mm-dd) : “);
bday = br.readLine();
System.out.print(“Comments : “);
comments = br.readLine();
System.out.print(“Favorite Dish : “);
favoritedish = br.readLine();
String query = “INSERT INTO profile ( ID, lastname, firstname, mi, address, landline,
cellphone, email, birthday, comments, favoritedish)
VALUES
“(?,?,?,?,?,?,?,?,?,?,?)”;
prepareStatement prepstmt = connection.prepareStatement (query);
preps.setInt(1,0);
prepstmt.setString(2,lastname);
prepstmt.setString(3,firstname);
prepstmt.setString(4,middleinit);
prepstmt.setString(5,address);
prepstmt.setString(6,landline);
prepstmt.setString(7,cellphone);
prepstmt.setString(8,email);
prepstmt.setDate(9, birthday.valueOf (bday));
prepstmt.setString(10, comments);
prepstmt.setString(11, favoritedish);
int row = prepstmt.executeUpdate();
System.out.println(“Thankyou for inputting the record of “ + firstname + “ “ + lastname);
System.out.println(row + “ record added”);
}
}
catch (IOException e) {
System.out.println(“I/O Error!”);
System.exit(1);
}
catch (SQLException ex) {
System.err.println(“SQLException: “ + ex.getMessage());
}
catch (IllegalArguementException err) {
System.out.println(“You have a wrong date format for the birthday!”)
System.out.println(“You should use the format yyyy-mm-dd. Ex. 1990-03-25”);
System.out.println(“Sorry, this record cannot be added now.”);
System.exit(1);
}
)
)