Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. package filmdatabase;
  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.  
  12. public class FilmDatabase {
  13.  
  14. private static String user, pass, host, serviceName;
  15. private static Connection conn;
  16. private static Scanner userInput;
  17.  
  18. public static void main(String[] args) throws SQLException {
  19. // TODO code application logic here
  20.  
  21. loadOracleJdbcDriver();
  22. connectToServer(user, pass, host, serviceName);
  23.  
  24. }
  25.  
  26. public FilmDatabase() {
  27.  
  28. }
  29.  
  30. public static void loadOracleJdbcDriver() {
  31. try {
  32. Class.forName("oracle.jdbc.driver.OracleDriver");
  33. } catch (ClassNotFoundException e) {
  34. System.out.println("Error -" + e.toString());
  35. System.out.println("Could not load the driver");
  36. }
  37.  
  38. }
  39.  
  40.  
  41. public static void connectToServer(String user, String pass,
  42. String host, String serviceName) throws SQLException {
  43.  
  44. try {
  45. Scanner sc = new Scanner(System.in);
  46. user = sc.next();
  47. pass = sc.next();
  48. host = sc.next();
  49. serviceName = "xe";
  50. System.out.println(user + " " + pass + " " + host);
  51.  
  52. System.out.println("Connecting to Database...");
  53.  
  54. // userid, password and hostname are obtained from the console
  55. try ( //try-with-resources
  56. Connection conn = DriverManager.getConnection("jdbc"
  57. + ":oracle:thin:"
  58. + user + "/" + pass + "@" + host + ":1521/"
  59. + serviceName)) {
  60.  
  61. /* JDBC default is to commit each SQL statement
  62. as it is sent to the database.
  63. Setting autocommmit=false
  64. changes the default
  65. behaviour so that transactions
  66. have to be committed explicity.
  67. */
  68. conn.setAutoCommit(false);
  69. }
  70.  
  71. } catch (SQLException e) {
  72. System.out.println("Error + " + e.toString());
  73. System.out.println("Connection Failure");
  74. }
  75. }
  76.  
  77.  
  78. public static void createFilmTable() throws SQLException {
  79. Statement s = conn.createStatement();
  80.  
  81.  
  82.  
  83.  
  84. }
  85.  
  86.  
  87. public static void populateFilmTable() {
  88.  
  89. }
  90.  
  91.  
  92. public static void getTitleAllFilms() throws SQLException, FileNotFoundException {
  93. FileInputStream film = new FileInputStream("src/Film.txt");
  94.  
  95. }
  96.  
  97.  
  98. public static void getTitleAllFilmsWithoutTitleTag() {
  99.  
  100. }
  101.  
  102.  
  103. public static void getActorNameGodFather() {
  104.  
  105. }
  106.  
  107.  
  108. public static void getTitleYearAllCrimeFilms() {
  109.  
  110. }
  111.  
  112.  
  113. public static void getTitleYearAllFilmsFtMarlonBrando() {
  114.  
  115. }
  116.  
  117. public static void getAllFilmsOneDirector() {
  118.  
  119. }
  120.  
  121.  
  122. public static void getTitleNameDirectorsMoreThanOneDirector() {
  123.  
  124. }
  125.  
  126.  
  127. public static void getNameActorAndDirectorSameFilm() {
  128.  
  129. }
  130.  
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement