jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes SQL Server 2000 Database Connection using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Server 2000 Database Connection using JDBC" Watch "SQL Server 2000 Database Connection using JDBC" New topic

SQL Server 2000 Database Connection using JDBC

Rajesh Rami Reddy

Joined: Mar 04, 2008
Posts: 5
Hello Friends,

I had wrote a programme for connecting the Sql Server 2000 DataBase using JDBC.Programe code is

import java.sql.*;

public class createTable
public static void main (String[] args)
DB db = new DB();
Connection conn=db.dbConnect(


class DB
public DB() {}

public Connection dbConnect(String db_connect_string,
String db_userid, String db_password )
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println ("connected");
return conn;

catch (Exception e)
return null ;

public void createTables(Connection conn)
String query;
Statement stmt;

query="create table cust_profile " +
"(name varchar(32), " +
"address1 varchar(50), " +
"city varchar(50), " +
"state varchar(50), " +
"country varchar(50))";
stmt = conn.createStatement();
stmt.executeUpdate( query);
catch (Exception e)

When i was run this programme it was displayed as

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DB.dbConnect(createTable.java:24)
at createTable.main(createTable.java:8)
at DB.createTables(createTable.java:51)
at createTable.main(createTable.java:11)

i had set the CLASSPATH as "C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\sqlserver.jar"

Could you know any one where i did a mistake. Please inform me at rajeshlab@yahoo.com
Jan Cumps

Joined: Dec 20, 2006
Posts: 2551

Try to find the one driver jar that you need, and add that to your classpath. It seems like you have added different (versions of?) sqlserver jars.

Try if putting the driver in a folder without spaces helps.

These people had a similar issue: Upgrading to SQL Server 2005 JDBC driver (SQLJDBC.jar) causes connection failure for exising SQLService
You will notice that the path is different in the SQL 2005 driver to that provided in the SQL 2000 driver.

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); // 2000 version

Regards, Jan

OCUP UML fundamental and ITIL foundation
I agree. Here's the link: http://aspose.com/file-tools
subject: SQL Server 2000 Database Connection using JDBC
It's not a secret anymore!