public class Getconnectionsqlserver {public void Getconnectionsqlserver () {String drivername = " Com.microsoft.sqlserver.jdbc.SQLServerDriver "; String Dburl = "Jdbc:sqlserver://133.96.46.100:1433;databasename=test"; 1433 is the port, "test" is the database name string userName = "Test"; User name string userpwd = "Test"; Password Connection dbconn = null;try {class.forname (drivername). newinstance ();} catch (Exception ex) {System.out.println (" Drive load Failed "); Ex.printstacktrace ();} try {dbconn = drivermanager.getconnection (Dburl, UserName, userpwd); SYSTEM.OUT.PRINTLN ("Connect database successfully! ");} catch (Exception e) {e.printstacktrace ();} finally {try {if (dbconn! = null) Dbconn.close ();} catch (SQLException e) {//To Do auto-generated catch Blocke.printstacktrace ();}}} public static void Main (string[] args) {getconnectionsqlserver getconn = new Getconnectionsqlserver (); Getconn.getconnectionsqlserver ();}}
SQL Server Test Connection