import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * * Created by arul on 3/14/2018. */ public class TestMSSQLConnection { public static void main(String[] argv) throws SQLException { if( !validate(argv) ) return; System.out.println("-------- MSSQL JDBC Connection Testing ------"); System.out.println(" JDBC Url: "+ argv[0]); System.out.println(" Username: "+ argv[1]); System.out.println(" Password: "+ argv[2]); try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { System.out.println("Where is your MSSQL JDBC Driver?"); e.printStackTrace(); return; } System.out.println("MSSQL JDBC Driver Registered!"); Connection connection = null; try { connection = DriverManager.getConnection( //"jdbc:MSSQL:thin:@//DAEAPIPORTAL16:1521/orcl.eur.ad.sag", "ADMIN", "PASSWORD"); argv[0], argv[1], argv[2]); } catch (SQLException e) { System.out.println("Connection Failed! Check output console"); e.printStackTrace(); return; } if (connection != null) { System.out.println("You made it, take control your database now!"); connection.close(); } else { System.out.println("Failed to make connection!"); } } private static boolean validate(String[] argv) { if( argv.length<3 ){ System.out.println("Usage: TestMSSQLConnection <> <> <>"); return false; } return true; } }