Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // The URL representing the ORACLE database connection string
  2. private static final String ORACLE_URL = "jdbc:oracle:thin:@aloe.cs.arizona.edu:1521:oracle";
  3.  
  4. // Start with null username and password
  5. String username = null;
  6. String password = null;
  7.  
  8. // Ensure that we got a username and password argument
  9. if (args.length == 2)
  10. {
  11. username = args[0];
  12. password = args[1];
  13. }
  14. else
  15. {
  16. System.err.println("Error reading command line arguments, expected username and password!");
  17. System.exit(-1);
  18. }
  19.  
  20. // Load the OracleDriver
  21. try
  22. {
  23. Class.forName("oracle.jdbc.OracleDriver");
  24. }
  25. catch (ClassNotFoundException exception)
  26. {
  27. System.err.println("Error loading the Oracle JDBC driver!");
  28. System.exit(-1);
  29. }
  30.  
  31. Connection dbConnection = null;
  32.  
  33. // Connect to the DB with the connection URL, given username and password
  34. try
  35. {
  36. dbConnection = DriverManager.getConnection(ORACLE_URL, username, password);
  37. }
  38. catch (SQLException exception)
  39. {
  40. System.err.println("Error connecting to the Oracle database!\nError: ");
  41. exception.printStackTrace();
  42. System.exit(-1);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement