Hello! I have written a simple program which connects netbeans with
SQL Server database. The program is giving an exception. I am
displaying the source code of my program and exception below. Please
guide me to solve this problem.
public class dbconnection {
Connection con = null;
public static void main(String args[]) throws ClassNotFoundException, SQLException{
try
{
Connection con = null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://SABOOR-PC\\SQLEXPRESS;databaseName = Test;integratedSecurity = true;");
Statement st = con.createStatement();
String sql = "SELECT *FROM Employees";
ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
String EmployeeName = rs.getString("EmpName");
String EmployeeWage = rs.getString("Wage");
System.out.println(EmployeeName + " "+ EmployeeWage);
}// end while
con.close();
}// end try
catch(ClassNotFoundException | SQLException sqlEx)
{
System.out.println(sqlEx);
}
}
}
Now I am also giving exception which is occuring:
"java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver"
As you can see above exception please tell me that why this exception is occuring and how can I handle this exception?