Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC for SQL Server 2000 Connection error 1

Status
Not open for further replies.

codo

IS-IT--Management
Oct 31, 2001
187
ID
I've installed the driver JDBC for Microsoft SQL Server 2000 and set the path on autoexec.bat like this :

SET CLASSPATH=.;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\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
PATH=C:\j2sdk142\BIN;%PATH%
SET CLASSPATH =.\;%CLASSPATH%


This is my java code :

import java.sql.*;

class Koneksi
{
public static void main(String[] args)
{
try
{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.1:1433;DatabaseName=Northwind,user=user,password=password");
con.close();
System.out.println("Connection Success..!!!");
System.exit(0);
}
catch(ClassNotFoundException eclass)
{
System.out.println("Driver Not Found !");
}
catch(SQLException esql)
{
System.out.println(esql.getMessage());
}
}
}


I run the compiled java and got this result :
" Driver Not Found ! "

Why it couldn't find the driver? is there something wrong with the Set Classpath command?
 
I would guess that because you have spaces in the directory names, java is not finding the drivers.

Try adding quotes :

SET CLASSPATH=.;"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\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar"

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I had change the classpath just like sedj said but still the result was "Driver not found".
Is there any ways to check driver already istalled? maybe through ODBC from XP Control Panel? how to make sure that the driver was really installed on my XP?
 
Well, the "driver installed" means the jar is in the classpath. How are you running your program?

Cheers,
Dian
 
I'm running using JCreator v2.0 and the result is "Driver Not Found". When i used debug to trace the programs it stop on " Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");" line and then jumped to

catch(ClassNotFoundException eclass)
{
System.out.println("Driver Not Found !");
}
and that's how the result.

But when i running it from command prompt using "java Koneksi.java" the result was :

Exception in thread "main" java.lang.noClassFoundError: Koneksi/java

I've no idea how to solve it.
 
Well, I have no idea of how to set classpath with JCreator, but with respect to command line, you first need to compile the program with

Code:
javac Koneksi.java

and run it with

Code:
java Koneksi

Cheers,
Dian


 
I do have compiled and run it from command line and still not worked. Now i've copy all the .jar files into same directory of Koneksi.java files and run it through command line and it work fine. So now i know that set the CLASPATH on autoexec.bat are useless or maybe XP never execute the Autoexec.bat or not recognized the Set Classpath command.
 
Didn't Windoze stop using autoexec.bat after Win98 ???

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Then what's the function of Sysconfig? i also set the classpath on XP's Enviroment Variables and still not function. Does anyone have an ide how to set the Classpath on XP?
 
This is what i typed on my XP Environment variables :

C:\.;"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\Microsoft SQL Server 2000 Driver for JDBC\lib\MSSQLSERVER.jar"

All the .jar files i changed to Uppercase. So tell me what's wrong with those lines.
 
On Win32, it does not actually matter about case sensitivity of jar files.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I don't like the c:\. thingie, makes no sense to me.

Try using the -cp option of java to set the classpath explicitilly.

Cheers,
Dian
 
OK. Lets start at the beginning.

Save the following code as C:\TestCon.java

Code:
import java.sql.*;

public class TestCon {
	public static void main(String[] args) throws Exception { 
		Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

		Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.1:1433;DatabaseName=Northwind,user=user,password=password");
    		if (con != null) {
    			con.close();
    		}
    		
    		System.out.println("Connection Success : " +con);
	}
}

Open a DOS command prompt.
Type :

Code:
cd \
javac TestCon.java

That should have generated C:\TestCon.class

Now to run it.

Set up your CLASSPATH :


Code:
set CLASSPATH=C:\;"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\Microsoft SQL Server 2000 Driver for JDBC\lib\MSSQLSERVER.jar"

And execute the code :
Code:
java TestCon

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thank's gusy for all your support, i've set the classpath through environment variables like this :

CLASSPATH=.;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\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar

(without " sign) and now i can connect to MSQL server Database. Thanks to timw for the link


Thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top