Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. package DatabaseAssignment2;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.Statement;
  9. import java.sql.SQLException;
  10. import java.util.Scanner;
  11. import oracle.jdbc.*;
  12. import oracle.net.aso.s;
  13. import oracle.xdb.XMLType;
  14.  
  15.  
  16. public class DatabaseAssignment2 {
  17.  
  18. private static String username, password, hostname, serviceName;
  19. private static Connection conn;
  20. private static Scanner userInput;
  21.  
  22. public static void main(String[] args) throws SQLException {
  23. // TODO code application logic here
  24.  
  25. loadOracleJdbcDriver();
  26. connectToServer(username, password, hostname, serviceName);
  27. //Statement s = conn.createStatement();
  28.  
  29. createFilmTable();
  30.  
  31. }
  32.  
  33. public DatabaseAssignment2() {
  34.  
  35. }
  36.  
  37. public static void loadOracleJdbcDriver() {
  38. try {
  39. Class.forName("oracle.jdbc.driver.OracleDriver");
  40. } catch (ClassNotFoundException e) {
  41. System.out.println("Error -" + e.toString());
  42. System.out.println("Could not load the driver");
  43. }
  44.  
  45. }
  46.  
  47.  
  48. public static void connectToServer(String username, String password,
  49. String hostname, String serviceName) throws SQLException {
  50.  
  51. try {
  52. Scanner sc = new Scanner(System.in);
  53. System.out.println("Type userid, password, hostname, servicename: ");
  54. username = sc.next();
  55. password = sc.next();
  56. hostname = sc.next();
  57. serviceName = "orcl";
  58. System.out.println(username + " " + password + " " + hostname);
  59.  
  60. System.out.println("Connecting to Database...");
  61.  
  62. // userid, password and hostname are obtained from the console
  63. //try-with-resources
  64. conn = DriverManager.getConnection("jdbc"
  65. + ":oracle:thin:"
  66. + username + "/" + password + "@" + hostname + ":1521/"
  67. + serviceName);
  68.  
  69. conn.setAutoCommit(false);
  70.  
  71.  
  72. } catch (SQLException e) {
  73. System.out.println("Error + " + e.toString());
  74. System.out.println("Connection Failure");
  75. }
  76.  
  77.  
  78. }
  79.  
  80. public static void createFilmTable() throws SQLException {
  81.  
  82. Statement s = conn.createStatement();
  83.  
  84.  
  85. s.executeUpdate("DROP TABLE ASS2_FILM");
  86. System.out.println("Table Dropped");
  87. s.executeUpdate("CREATE TABLE ASS2_FILM(fnum VARCHAR(20) " +
  88. "CONSTRAINT fnum_PK PRIMARY KEY, " +
  89. " film SYS.XMLTYPE)");
  90.  
  91. System.out.println("Made");
  92.  
  93. }
  94.  
  95. public static void populateFilmTable() {
  96.  
  97. }
  98.  
  99.  
  100. public static void showTitleOfAllFilms() {
  101.  
  102. }
  103.  
  104.  
  105. public static void showTitleOfAllFilmWithoutTitleTags() {
  106.  
  107. }
  108.  
  109.  
  110. public static void showNamesOfActorsWhoAppearedInGodfather() {
  111.  
  112. }
  113.  
  114.  
  115. public static void showTitleAndYearOfAllCrimeFilms() {
  116.  
  117. }
  118.  
  119.  
  120. public static void showTitleAndYearOfAllFilmsMarlonBrando() {
  121.  
  122. }
  123.  
  124. public static void showOneDirectorFilms() {
  125.  
  126. }
  127.  
  128.  
  129. public static void showTitleAndNamesMoreThanOneDirector() {
  130.  
  131. }
  132.  
  133.  
  134. public static void ShowTheNamesOfActorsAndSoleDirectorOfSameFilm() {
  135.  
  136. }
  137.  
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement