MSSQL database connection problem
Hi,
I got problems trying to connect to database using JDBC. Problem is following:
Code:
String sql ="select * from table";
Connection conn =null;
try
{
String url ="jdbc:sqlserver://dbserver:1433/databasename";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url,"usename","password");
}
catch(Exception e)
{
System.out.println(e);
}
Trying to run this, I get error:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
Now I think this tells that classpath is not set right, but I have commanded:
SET CLASSPATH = C:\path\to\sqljdbc.jar but it still won't work. Any ideas?
My database is MS SQL Server 2005 running on another server than my java application.
[1190 byte] By [
Akulaaria] at [2007-11-27 9:43:40]

# 3
> or you can put the jar file in the java folder
>
> e.g.
> C:\j2Se1.6\jre\lib\ext\mssql.jar;
Take care. As long as you know nothing about the running environment and the purposes of the Java program, don't suggest those nasty hacks.
The classpath used depends on the running environment created/used. The environment variable $classpath will only be used if you execute the Java class as an Java Application using java.exe in the operating system's command console. If you're executing it as a JAR file, then you need to add the path to the MSSQL JAR to the class-path entry of the manifest.mf file. If you're executing it inside an IDE, then you need to add the path to the MSSQL JAR to the Build Path of the project. Etcetera ..
# 4
>Take care. As long as you know nothing about the running environment and the purposes >of the Java program, don't suggest those nasty hacks.
I just made easy for him...
but if Akulaari is using windows the easiest way is to right click my computer
find environment variable button and edit classpath.. if your mssql.jar is located in
c:\mssql.jar, add ;c:\mssql.jar to your classpath. save!!!