Tuesday, March 1, 2011

Connect to MS SQL Northwind sample from Java


(See below for update when running on x64 platform)

I just printed these names from Microsoft’s sample NorthWind database.

Here are the steps I used:

  1. I installed the Northwind database:
    1. download from here:
    2. copy the files to a new folder C:\Databases
    3. started SQL Server Management Studio
    4. Attached Northwind.mdb
  2. Enabled TCP/IP connection on my SQL Server using SQL Server Configuration Manager
    1. You need to restart the service (I used Windows services manager)
  3. Installed JDBC driver from MS:
    1. download from here
    2. unzipped it to C:\Program Files\Microsoft SQL Server JDBC Driver 3.0
    3. copied sqljdbc_auth.dll
      1. from C:\Program Files\Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86
      2. to C:\WINDOWS\system32
  4. Used Netbeans to make a new Java Application and
    1. set the Main class as follows
package jdbctest;


import java.sql.*;


public class Main {


    public static void main(String[] args) {


        // Create a variable for the connection string.

        String connectionUrl = "jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;"

                + "databaseName=Northwind;integratedSecurity=true;";


        // Declare the JDBC objects.

        Connection con = null;

        Statement stmt = null;

        ResultSet rs = null;


        try {

            // Establish the connection.


            con = DriverManager.getConnection(connectionUrl);


            // Create and execute an SQL statement that returns some data.

            String SQL = "SELECT TOP 10 * FROM dbo.customers";

            stmt = con.createStatement();

            rs = stmt.executeQuery(SQL);


            // Iterate through the data in the result set and display it.

            while (rs.next()) {

                System.out.println(rs.getString(4) + " " + rs.getString(6));


        } // Handle any errors that may have occurred.

        catch (Exception e) {


        } finally {

            if (rs != null) {

                try {


                } catch (Exception e) {



            if (stmt != null) {

                try {


                } catch (Exception e) {



            if (con != null) {

                try {


                } catch (Exception e) {






    1. I copied this from the samples in:

      C:\Program Files\Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\help\samples\connections\connectURL.java

    2. the URL string is:

      "jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;" + "databaseName=Northwind;integratedSecurity=true;"

    3. the SQL statement is:

      "SELECT TOP 10 * FROM dbo.customers"

    4. set the application libraries to include sqljdbc4.jar


      you’ll find it:

      C:\Program Files\Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu

I actually did more than this, but I’ve left out the false starts.

When running under NetBeans on a Windows 7 (X64) platform

I had to copy the “correct” sqljdbc_auth.dll  to the top folder of project being tested.


The “correct” DLL is the one for the JVM running – not the Windows platform.

Unless you have done something “special” you are most likely running the x32 version of the JVM.

Tuesday, December 28, 2010

Infiltration Alert Virus attacked my notebook

My notebook is running Windows 7 Home Premium 64bit.

It was infected by a series Trojan viruses that displayed 4 symptoms:

  1. Outlook 2003 stopped showing non-embedded images
    (This was because the trojan had turned on Internet Explorer’s Proxy settings and was directing all Internet traffic to itself. I use FireFox so I didn’t notice)
  2. Some hours later, I started to get popup windows that warned of an infiltration alert while running a fake anti-virus scanner.
    1. I found each of these using task manager, killed the process and deleted the offending EXE which was usually within my User Application Data folders
    2. Variations of this virus kept reappearing
    3. each variation offered to fix my problem by installing an anti-virus package
  3. The virus then started up IE and directed me to porn sites or displayed pages that told me my computer was infected and directed me to sites that would fix my problem
  4. The viruses became more aggressive and started deleting processes
    1. sometimes the virus warned that the EXE had become infected and again offered to install the solution
    2. I could not start task manager or my anti-virus software.

Eventually I rebooted in safe mode (see here to see how) and tried various free anti-virus scanners:

  1. "AVG Anti-Virus Free” found nothing (and was the solution being used when the PC became infected)
  2. McAfee VirusScan” and “Microsoft Security Essentials” each found and deleted some viruses
  3. http://www.malwarebytes.org/ found and deleted the offending trojans

Here is an incomplete list of anti-virus solutions that does not include malwarebytes.

This tutorial gives some background.

I am currently running belt and braces:

Here is the Malwarebytes log file:

Malwarebytes' Anti-Malware



Database version: 5402


Windows 6.1.7600 (Safe Mode)

Internet Explorer 8.0.7600.16385


27/12/2010 9:43:28 PM

mbam-log-2010-12-27 (21-43-28).txt


Scan type: Quick scan

Objects scanned: 156278

Time elapsed: 2 minute(s), 31 second(s)


Memory Processes Infected: 0

Memory Modules Infected: 0

Registry Keys Infected: 0

Registry Values Infected: 5

Registry Data Items Infected: 0

Folders Infected: 0

Files Infected: 3


Memory Processes Infected:

(No malicious items detected)


Memory Modules Infected:

(No malicious items detected)


Registry Keys Infected:

(No malicious items detected)


Registry Values Infected:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\mbbloqvs (Trojan.FakeAlert) -> Value: mbbloqvs -> Quarantined and deleted successfully.

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell (Trojan.Agent) -> Value: Shell -> Quarantined and deleted successfully.

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\SysMap.NET (Trojan.Agent) -> Value: SysMap.NET -> Quarantined and deleted successfully.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\abhqgrhe (Trojan.FakeAlert.Gen) -> Value: abhqgrhe -> Quarantined and deleted successfully.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\lcdgdvcm (Trojan.FakeAlert.Gen) -> Value: lcdgdvcm -> Quarantined and deleted successfully.


Registry Data Items Infected:

(No malicious items detected)


Folders Infected:

(No malicious items detected)


Files Infected:

c:\Users\John\AppData\Local\Temp\pqnwiwvmd\sydyluulajb.exe (Trojan.FakeAlert) -> Quarantined and deleted successfully.

c:\Users\John\AppData\Local\Temp\0.9150089036818203.exe (Trojan.FakeAlert) -> Quarantined and deleted successfully.

c:\Users\John\AppData\Local\Wdcfg3xx\sysmap.net.dll (Trojan.Agent) -> Quarantined and deleted successfully.