Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I need to connect a J# app to SQL Server 2000 using JDBC.

Sadly, I can't 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. ;)

Posted

Here is the source code for what I have come up with..

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...