title: How do you configure a DataSource in Java to connect to MS SQL Server?
body: <p>I'm trying to follow Java's JDBC tutorials to write a Java program that can connect to SQL Server 2008.  I'm getting lost at the point of making a connection.</p>
  
  <p>The following snippet is from the tutorial:</p>
  
  <pre><code>InitialContext ic = new InitialContext();
  DataSource ds = ic.lookup("java:comp/env/jdbc/myDB");
  Connection con = ds.getConnection();
  DataSource ds = (DataSource) org.apache.derby.jdbc.ClientDataSource()
  ds.setPort(1527);
  ds.setHost("localhost");
  ds.setUser("APP")
  ds.setPassword("APP");
  Connection con = ds.getConnection(); 
  </code></pre>
  
  <p>There's no explanation of what comp/env/jdbc/myDB should point to, and I don't know how I should choose a port.  Also, the object ds seems to be defined twice.</p>
  
  <p>I'm using the <code>JSQLDataSource</code> driver, for the record.  Can anyone point me in the right direction here?</p>
  
  <p><a href="http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html" rel="noreferrer">http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html</a></p>