Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class JdbcSQLServerConnection {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. if (args.length != 3) {
  6. System.out.println("Usage :njava -jar jarFile.jar url username password");
  7. System.exit(0);
  8. }
  9. Connection conn = null;
  10. try {
  11. String dbURL = args[0];
  12. String user = args[1];
  13. String pass = args[2];
  14. conn = DriverManager.getConnection(dbURL, user, pass);
  15. if (conn != null) {
  16. DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
  17. System.out.println("Driver name: " + dm.getDriverName());
  18. System.out.println("Driver version: " + dm.getDriverVersion());
  19. System.out.println("Product name: " + dm.getDatabaseProductName());
  20. System.out.println("Product version: " + dm.getDatabaseProductVersion());
  21. }
  22. } catch (SQLException ex) {
  23. ex.printStackTrace();
  24. } finally {
  25. try {
  26. if (conn != null && !conn.isClosed()) {
  27. conn.close();
  28. }
  29. } catch (SQLException ex) {
  30. ex.printStackTrace();
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement