title: Microsoft SQL Server 2012 database connectivity with Java (version 8 or 1.8) With example?
body: <pre><code>  -please give some democode
  
          import java.sql.Connection;
          import java.sql.DriverManager;
          import java.sql.ResultSet;
          import java.sql.SQLException;
          import java.sql.Statement;
          public class JDBCConnectivity
          {
              public static void main(String[] args) throws ClassNotFoundException 
              {       String url = "jdbc:sqlserver://localhost:1433//MSSQLSERVER;databaseName=jdbcexample";
                      String user="",password="";
                      try
                      {
                          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                          Connection con = DriverManager.getConnection(url,user,password); 
                          Statement s1 = con.createStatement();
                          ResultSet rs = s1.executeQuery("SELECT * FROM sample");
                          if(rs!=null)
                          {
                              while (rs.next())
                              {
                                   System.out.println(rs.getString(1));
  
                              }
                          }
                      }
                      catch(SQLException e)
                      {
                          e.printStackTrace();
                      }
              }
          }
  </code></pre>
  
  <p>Hi techie Im using netbeans IDE, im unable to connect to SQL Server2012. 
  default TCP port number is 1433 but still it shows invalid port number. </p>