Hai, i am tried to use the SQL Server with Java and Tomcat 5.0 Application Server.
I am using the JDBC Driver for Java connecting with SQL Server. I m using SQL Server 2005. But the JDBC Connection doesn't create.
I have used the following code for java database connectivity with SQL Server

import java..sql.*;
public class Test {
public static void main(Sring[] args)
{
try
{
//load the driver class
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433; DatabaseName=timetracking ");
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch (SQLException sqle)
{
System.err.println(sqle);
}

The above code was compiled successfully, but it's not running. The below error was raised. I have coped and paste it the JDBC Driver class for SQL Server 2005(sqljdbc.jar) to theWEB-INF/lib folder.

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

I don't know what i am doing with wrong. If anybody know, how to solve this, kindly post me.

Thanks

Tamilvanan

have you actually added the required classes to your classpath when running your application?

Yes, i have put the corresponding class file to the path. when I tried to rectify this error another one error could be invoked, that error is...

May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:23 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:24 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
May 16, 2007 9:13:24 AM java.util.jar.Attributes read
WARNING: Duplicate name in Manifest: Class-Path
java.sql.SQLException: No suitable driver

what's wrong with my same code, no changes made...

Thanks for your useful reply.


Tamilvanan

sounds like a bad jar file. Impossible to say which though (but most likely your own).

Hai,
Now its working fine, Thank you for all your replies.

Will meet you later.

Thanks & Regards

Tamilvanan

Would be nice if you tell us how you sorted, so people with similar problem can look at it

I had to do one settings in SQL Server Configuration Manager
Select Protocols for MSSQLSERVER under the SQL Server 2005 Network Configuration. Then Enable the TCP/IP Protocol.

And then i has to delete the old Driver(jar) file in the specified classpath, and then put the Driver File freshly.

Then i has been connected with SQL Server 2005.


Thanks

Tamilvanan

i am a fresher in java . i got the same error again and again ..
i set the class path like

set path="C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\sqljdbc.jar";

also i made the changes in tcp/ip.

the code is compiling correctly. and when i am running its showing the raised exception
please help me ,

//////////////////////////////Code///////////////////////////
import java.sql.*;
import java.io.*;
public class db
{
/**/ 
static String username= "xxxxxx";
static String password= "xxxxxx";
static String thincon =  "jdbc:freetds:sqlserver://local/JavaTest";
static String driverclass = "com.internetcds.jdbc.tds.Driver";
/**/
public static Connection GetConnection() throws SQLException
    {
     Connection cn = null;
     try
        {
         Driver d = (Driver)Class.forName(driverclass).newInstance();
         cn=DriverManager.getConnection(thincon,username,password);
         return cn;
        }
     catch(Exception e) 
        {
            e.printStackTrace(System.out);
            throw new SQLException("Error loading JDBC Driver");
        }
    }

public static void main(String args[])
{
    try
    {
        Connection conn = getConnection();
        if(conn==null)
        {
            System.out.println("Connection is null");
            System.exit(0);
        }
        else
        {
            boolean b = conn.getAutoCommit();
            System.out.println("Connection ok");
            System.out.println("AutoCommit"+b);

        }
    }   
    catch(SQLException e)
    {
        e.printStackTrace();

    }
    }
}
//////////////////////////////Exception/////////////////////

 java db
Exception in thread "main" java.lang.NoClassDefFoundError: db
Caused by: java.lang.ClassNotFoundException: db
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
/////////////////////////////////////////////////////////////////////////

please help me for correcting this error . . .

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.