Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

SQL Server 2000 Database Connection using JDBC

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic