Versions Compared

Key

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

...

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));
        }
    }
}

 

c) Connect with C#

 

Code Block
themeFadeToGreyConfluence
languagec#
linenumberstrue
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;

namespace SecureSQL
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = "Server=sqlseclab-lsnr1.its.yale.edu;" + 
                                              "Initial Catalog=master;" +
                                              "Integrated Security=true;" +
                                              "Encrypt=True;TrustServerCertificate=False";
                connection.Open();
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = "select GetDate()";
                    command.CommandType = CommandType.Text;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0}", reader[0]);
                        }
                    }
                }

                Console.ReadLine();
            }
        }
    }
}

...