import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcSQLServerConnection {
public static void main(String[] args) throws ClassNotFoundException {
Connection conn = null;
try {
String url = "jdbc:sqlserver://microsoft\\SQLEXPRESS;databaseName=crud";
String userName = "sa";
String password = "pwd";
System.out.println("Connected2");
Class.forName("com.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Connected");
if (conn != null) {
DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
System.out.println("Driver name: " + dm.getDriverName());
System.out.println("Driver version: " + dm.getDriverVersion());
System.out.println("Product name: " + dm.getDatabaseProductName());
System.out.println("Product version: " + dm.getDatabaseProductVersion());
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}
output:-
Connected2 Exception in thread "main" java.lang.ClassNotFoundException: com.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at JdbcSQLServerConnection.main(JdbcSQLServerConnection.java:28)I have included sqljdbc4.jar in eclipse library but still it is not working on my system please help me in this solution`enter code here.
com.microsoft.sqlserver.jdbc.SQLServerDriver
, notcom.sqlserver.jdbc.SQLServerDriver
– Mark Rotteveel