Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

c) Connect with Java using Microsoft's JDBC driver

 

Code Block
languagejava
linenumberstrue
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;

public class Main {
    public static void main(String[] args)
       throws SQLException {
        String connectionUrl =
                "jdbc:sqlserver://sqlseclab-lsnr1.its.yale.edu:1433;" +
                "databaseName=master;user=sa;password=userpassword;" +
                "encrypt=true;trustServerCertificate=false;" +
                "trustStore=/Users/mpoddar/IdeaProjects/keystore;" +
                "trustStorePassword=keystorepass";
        Connection connection = DriverManager.getConnection(connectionUrl);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select GetDate()");
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
        }
    }
}

...

c) Connect with Java using JTDS JDBC driver

Code Block
languagejava
linenumberstrue
import java.sql.*;
import net.sourceforge.jtds.jdbc.*;

public class Main {
    public static void main(String[] args)
       throws SQLException {
        System.setProperty("javax.net.ssl.trustStore", "/Users/mpoddar/IdeaProjects/keystore" );
        System.setProperty("javax.net.ssl.trustStorePassword","keystorepassword");
        String connectionUrl =
                "jdbc:jtds:sqlserver://sqlseclab-lsnr1.its.yale.edu:1433/master;" +
                        "domain=yale;user=ap349;password=password;useNTLMv2=true;" +
                        "ssl=authenticate";
        Connection connection = DriverManager.getConnection(connectionUrl);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select GetDate()");
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
        }
    }
}