Advertisement
Guest User

Untitled

a guest
Nov 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. import java.io.*;
  2. import java.sql.*;
  3.  
  4. class Assignment {
  5.  
  6. private static String readEntry(String prompt)
  7. {
  8. try
  9. {
  10. StringBuffer buffer = new StringBuffer();
  11. System.out.print(prompt);
  12. System.out.flush();
  13. int c = System.in.read();
  14. while(c != '\n' && c != -1) {
  15. buffer.append((char)c);
  16. c = System.in.read();
  17. }
  18. return buffer.toString().trim();
  19. }
  20. catch (IOException e)
  21. {
  22. return "";
  23. }
  24. }
  25.  
  26. /**
  27. * @param conn An open database connection
  28. * @param productIDs An array of productIDs associated with an order
  29. * @param quantities An array of quantities of a product. The index of a quantity correspeonds with an index in productIDs
  30. * @param orderDate A string in the form of 'DD-Mon-YY' that represents the date the order was made
  31. * @param staffID The id of the staff member who sold the order
  32. */
  33. public static void option1(Connection conn, int[] productIDs, int[] quantities, String orderDate, int staffID)
  34. {
  35. // Incomplete - Code for option 1 goes here
  36. }
  37.  
  38. /**
  39. * @param conn An open database connection
  40. * @param productIDs An array of productIDs associated with an order
  41. * @param quantities An array of quantities of a product. The index of a quantity correspeonds with an index in productIDs
  42. * @param orderDate A string in the form of 'DD-Mon-YY' that represents the date the order was made
  43. * @param collectionDate A string in the form of 'DD-Mon-YY' that represents the date the order will be collected
  44. * @param fName The first name of the customer who will collect the order
  45. * @param LName The last name of the customer who will collect the order
  46. * @param staffID The id of the staff member who sold the order
  47. */
  48. public static void option2(Connection conn, int[] productIDs, int[] quantities, String orderDate, String collectionDate, String fName, String LName, int staffID)
  49. {
  50. // Incomplete - Code for option 2 goes here
  51. }
  52.  
  53. /**
  54. * @param conn An open database connection
  55. * @param productIDs An array of productIDs associated with an order
  56. * @param quantities An array of quantities of a product. The index of a quantity correspeonds with an index in productIDs
  57. * @param orderDate A string in the form of 'DD-Mon-YY' that represents the date the order was made
  58. * @param deliveryDate A string in the form of 'DD-Mon-YY' that represents the date the order will be delivered
  59. * @param fName The first name of the customer who will receive the order
  60. * @param LName The last name of the customer who will receive the order
  61. * @param house The house name or number of the delivery address
  62. * @param street The street name of the delivery address
  63. * @param city The city name of the delivery address
  64. * @param staffID The id of the staff member who sold the order
  65. */
  66. public static void option3(Connection conn, int[] productIDs, int[] quantities, String orderDate, String deliveryDate, String fName, String LName,
  67. String house, String street, String city, int staffID)
  68. {
  69. // Incomplete - Code for option 3 goes here
  70. }
  71.  
  72. /**
  73. * @param conn An open database connection
  74. */
  75. public static void option4(Connection conn)
  76. {
  77. // Incomplete - Code for option 4 goes here
  78. }
  79.  
  80. /**
  81. * @param conn An open database connection
  82. * @param date The target date to test collection deliveries against
  83. */
  84. public static void option5(Connection conn, String date)
  85. {
  86. // Incomplete - Code for option 5 goes here
  87. }
  88.  
  89. /**
  90. * @param conn An open database connection
  91. */
  92. public static void option6(Connection conn)
  93. {
  94. // Incomplete - Code for option 6 goes here
  95. }
  96.  
  97. /**
  98. * @param conn An open database connection
  99. */
  100. public static void option7(Connection conn)
  101. {
  102. // Incomplete - Code for option 7 goes here
  103. }
  104.  
  105. /**
  106. * @param conn An open database connection
  107. * @param year The target year we match employee and product sales against
  108. */
  109. public static void option8(Connection conn, int year)
  110. {
  111. // Incomplete - Code for option 8 goes here
  112. }
  113.  
  114. public static Connection getConnection()
  115. {
  116. String user;
  117. String passwrd;
  118. Connection conn;
  119.  
  120. try
  121. {
  122. Class.forName("oracle.jdbc.driver.OracleDriver");
  123. }
  124. catch (ClassNotFoundException x)
  125. {
  126. System.out.println ("Driver could not be loaded");
  127. }
  128.  
  129. user = readEntry("Enter database account:");
  130. passwrd = readEntry("Enter a password:");
  131. try
  132. {
  133. conn = DriverManager.getConnection("jdbc:oracle:thin:@daisy.warwick.ac.uk:1521:daisy",user,passwrd);
  134. return conn;
  135. }
  136. catch(SQLException e)
  137. {
  138. System.out.println("Error retrieving connection");
  139. return null;
  140. }
  141. }
  142.  
  143. public static void main(String args[]) throws SQLException, IOException
  144. {
  145. // You should only need to fetch the connection details once
  146. Connection conn = getConnection();
  147.  
  148. // Incomplete
  149. // Code to present a looping menu, read in input data and call the appropriate option menu goes here
  150. // You may use readEntry to retrieve input data
  151.  
  152. conn.close();
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement