aspose file tools*
The moose likes JDBC 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Server 2000 Database Connection using JDBC" Watch "SQL Server 2000 Database Connection using JDBC" New topic
Author

SQL Server 2000 Database Connection using JDBC

Rajesh Rami Reddy
Greenhorn

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(
"jdbc:sqlserver://localhost:1433/tempdb","sa","manager");

db.createTables(conn);
}
}

class DB
{
public DB() {}

public Connection dbConnect(String db_connect_string,
String db_userid, String db_password )
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println ("connected");
return conn;

}
catch (Exception e)
{
e.printStackTrace();
return null ;
}
}

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

try
{
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);
stmt.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
};


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)
java.lang.NullPointerException
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
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

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
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Server 2000 Database Connection using JDBC
 
Similar Threads
Trying to grab the last record.
cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6
Mysql JDBC Cant load.....
Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000
Viewing data from database into an xls format not working