J# using JDBC with SQL Server

RobertStout

New member
Joined
Feb 14, 2005
Messages
2
Hi,

I need to connect a J# app to SQL Server 2000 using JDBC.
Sadly, I cant use ADO.NET as one of the restrictions is no ms extensions.

I have the SQL Server 2000 Driver for JDBC installed. I assume I will need it?

Can anyone point me in the right direction?

Thank you. ;)
 
Here is the source code for what I have come up with..

Code:
try
{
        // Register the driver
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

        // Pass connection URL
        Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver:[I]//SERVERNAME[/I]:[I]1433[/I]", "[I]USERNAME[/I]", "[I]PASSWORD[/I]");

        Statement stmt = conn.createStatement();

        ResultSet rs = stmt.executeQuery("SELECT * FROM CLDatabases");

        // Test data retrieval (first two table columns)
        while (rs.next()) ;
        {
                String colOne = rs.getString("DATABASEKEY");
                String colTwo = rs.getString("SERVERTYPE");
                System.out.println( colOne + "	" + colTwo );
        }
}
catch (Exception ex)
{
        ex.printStackTrace();
}

In the actual code, the italic text is set to (I believe) the relevant arguments.

This statement:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

Causes the following exception:
[java.lang.ClassNotFoundException]{"com.microsoft.jdbc.sqlserver.SQLServerDriver"}java.lang.ClassNotFoundException

Any ideas on why this exception is being thrown by this statement?

Thanks,
Rob
 
Back
Top