import java.sql.*;
public class MysqlConnect {
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "\\host/context/";
String dbName = "theDatabaseName";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver ";
String userName = "theUserName";
String password = "thePassword";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url + dbName, userName, password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
I am facing problem while the running this code.
I have already downloaded the SQL Server driver (sqljdbc), set it in the class path and copied it into the java/lib directory, but still I am getting the same result: ClassNotFoundException.
Can anybody help me?
You don’t have ‘com.microsoft.sqlserver.jdbc.SQLServerDriver’ class in your classpath.
Make sure you have following jars in your CLASSPATH: Msbase.jar, Msutil.jar, Mssqlserver.jar
More details here: http://support.microsoft.com/kb/313100