Advertisement
Guest User

jdbsee

a guest
Nov 12th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.Connection;
  3. import java.sql.SQLException;
  4.  
  5. public class TestJDBC {
  6. public static void main(String[] argv) {
  7. System.out.println("-------- Oracle JDBC Connection Testing ------");
  8. String URL = "jdbc:oracle:thin:@localhost:1521:xe"; // xe stand for Oracle XE db name
  9. String USERNAME = "system";
  10. String PASSWORD = "system";
  11. // this is the password you set when you installed XE.
  12. try {
  13. Class.forName("oracle.jdbc.driver.OracleDriver");
  14. } catch (ClassNotFoundException e) {
  15. System.out.println("Where is your Oracle JDBC Driver?");
  16. e.printStackTrace();
  17. return;
  18. }
  19. System.out.println("Oracle JDBC Driver Registered!");
  20. Connection connection = null;
  21.  
  22. try {
  23. //connection = DriverManager.getConnection(
  24. //"jdbc:oracle:thin:@localhost:1521:xe", "SYSTEM",
  25. //"1234");
  26. connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  27. } catch (SQLException e) {
  28. System.out.println("Connection Failed! Check output console");
  29. e.printStackTrace();
  30. return;
  31. }
  32. if (connection != null) {
  33. System.out.println("You made it, take control your database now!");
  34. } else {
  35. System.out.println("Failed to make connection!");
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement