Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public static void main(String[] args){
  2.  
  3. // note: the application running on localhost:1433 is ACTUALLY
  4. // an MS SQL Server instance!
  5. String jdbcUrl = "jdbc:mysql://localhost:1433/my-db";
  6.  
  7. // enable JDBC Driver Manager logging
  8. DriverManager.setLogWriter(new PrintWriter(System.err));
  9.  
  10. // set a timeout of 5 seconds for connecting (which is blissfully ignored!)
  11. DriverManager.setLoginTimeout(5);
  12.  
  13. // open the connection (which should fail, but freezes instead)
  14. try (Connection c = DriverManager.getConnection(jdbcUrl)){
  15. System.out.println("This should never be reached due to wrong JDBC URL.");
  16. }catch(Exception e){
  17. System.out.println("This is expected (but never printed).");
  18. }
  19. System.out.println("This is never printed either.");
  20. }
Add Comment
Please, Sign In to add comment