This is my code for connecting to the Server remotely. One thing more i would like to tell you guys that this code works only i am within my home network (the network in which server is installed) but i am unable to access it from other network hey guys please fix it thanks in advance
public class SQLServerDemo
{
public static void main(String[] args)
{
// TODO code application logic here
try {
System.out.println("Hello from try");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://192.168.0.2:1433;user=demo;password=demo;databaseName=SQL_Demo";
Connection conn = DriverManager.getConnection(url);
if (conn != null)
{
System.out.println("Connected");
} else if (conn == null)
{
System.out.println("NotConnected");
}
String queryString = "select * from UserDetail";
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
}
catch (Exception e)
{
System.out.println("Exception: "+e.getMessage());
e.printStackTrace();
}
}
}
Exception
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host GAUTAM-VAIO, port 1433 has failed.
Error: "null. Verify the connection properties.
Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port.
Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)