I am a newbie in java and I'm developing a Java EE application on the Netbeans 6.9.1 IDE. I have to connect my java application with SQL Server 2005.
For that I have downloaded the sqljdbc.jar file and have put it into C:Program Files (x86)Microsoft SQL ServerJDBC Drverlib
on my system and have set its classpath on command prompt like this
set classpath=.;C:Program Files (x86)Microsoft SQL ServerJDBC Drverlibsqljdbc.jar
and have set the classpath in the IDE by right clicking on the main project and selecting its property selecting libraries. Then in compile tab added a sqljdbc.jar
, but when I execute this code
import java.sql.*;
/**
*
* @author abc
*/
public class DBConnection
{
public Connection dbConnect(String db_connect_string)
{
try
{
Class.forName(
"com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn =
DriverManager.getConnection(db_connect_string);
System.out.println("connected");
return conn;
}
catch (Exception e)
{
System.out.println(e);
e.printStackTrace();
return null;
}
}
}
it is giving me ClassNotFound error on this line Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…