Java.Lang.Classnotfoundexception: Com.Microsoft.Sqlserver.Jdbc.Sqlserverdriver [Solution]
This error comes when you lot effort to connect to Microsoft SQL Server database from Java computer program but the required JDBC driver is non available inward Classpath or driver is available inward CLASSPATH but the class loader is non able to discovery it due classpath intricacies. Depending upon your situation, a solution could endure every bit uncomplicated every bit downloading whatever of sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar, based upon the Java version you lot are using as well as adding them into CLASSPATH every bit set CLASSPATH = %CLASSPATH%; (path to Microsoft JDBC driver) inward Windows. BTW, inward most of the cases "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" comes because of classpath intricacies. For example, if your Java computer program is using -cp or -classpath selection but you lot added the JAR into CLASSPATH surroundings variable or vice-versa.
Similarly, inward Java spider web application JDBC drivers are required to endure nowadays inward WEB-INF/lib directory or if you lot are running on Tomcat as well as then tomcat/lib directory every bit well. Finding solution becomes tardily 1 time you lot know how classpath concept plant inward Java, a must know for whatever Java developer.
Let's effort to discovery out the existent crusade of java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver as well as how to solve this nasty fault which is preventing your Java computer program to connect to Microsoft SQL Server 2008, 2012 or fifty-fifty 2014 database.
By the way, if you lot actually desire to empathise Java database programming from scratch, I advise you lot read the book, Practical database programming amongst Java book yesteryear Ying Bai. This mass explains every of import especial of Java database connectivity as well as JDBC amongst the uncomplicated example.
This Driver implementation shape is a must for connecting to database. If you lot know the piffling fleck of history, at that spot are 4 types of JDBC drivers, but straightaway days almost all database back upwards type 4, pure Java JDBC driver, which comes every bit JAR file as well as quite tardily to use.
All you lot require to produce is include those JAR e.g. mysql-connector.jar for MySQL, ojdbc6.jar for Oracle 11g database as well as sqljdbc4.jar for SQL Server into your Java application's classpath.
Sometimes you lot may discovery that at that spot is fifty-fifty multiple JDBC driver JAR available for the same database e.g. sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar for MSSQL database. This is because of unlike JDBC version available inward unlike JREs.
The latest version of JDBC is JDBC 4.1 released inward Java 7, which is supported yesteryear Microsoft inward sqljdbc41.jar, as well as you lot must role this JAR if you lot are connecting Microsoft SQL Server 2008 or 2012 from Java 1.7 or Java 1.8. If you lot role this JAR amongst JRE version less than 1.7, you lot volition acquire exception e.g. SQLFeatureNotSupportedException.
Similarly, if you lot are connecting to SQL Server database from Java 1.6 as well as then role sqljdbc4.jar, which supports JDBC 4.0 version, using this JAR inward Java 1.5 volition upshot inward Exception. Similarly, if you lot are connecting to MSSQL database from JRE 1.5 as well as then role sqljdbc.jar, which uses JDBC 3.0.
See Core Java Volume II Advanced Features yesteryear Cay S. Horstmann to acquire to a greater extent than most novel JDBC features introduced inward JDBC 3.0 as well as JDBC 4.0 on JDK 7.
As a upshot of this method telephone band JVM (class loader) volition hold off for a shape com.microsoft.sqlserver.jdbc.SQLServerDriver inward your Java program's classpath. If it doesn't flora the shape it throws "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver".
In total Java, it could endure your uncomplicated Java computer program which is executing this delineate of piece of work as well as inward firm Java, it could endure a web server or firm server or a framework executing this code on your behalf.
1) Check if you lot receive got downloaded JDBC Driver for Microsoft SQL Server i.e. whatever of sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar, if non as well as then delight download it from hither http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774 as well as add together into CLASSPATH of your Java program.
2) Make certain you lot download the right JDBC driver JAR for SQL SERVER depending upon your Java version e.g. sqljdbc.jar if you lot are connecting to Microsoft SQL server from Java 1.5, sqljdbc4.jar if you lot are running Java 1.6 or sqljdbc41.jar if you lot are using Java 1.7 or Java 8.
3) Make certain you lot solely add together 1 of these JAR, non all or them or fifty-fifty 2 of them.
4) If you lot are connecting to Microsoft SQL Server from Tomcat or whatever firm server e.g. JBoss or Weblogic, as well as then brand certain you lot include MSSQL JDBC driver JAR inward WEB-INF/lib directory. Sometimes, you lot likewise require to add together this into tomcat/lib if at that spot are multiple application which is connecting to SQL Server.
5) For total Java application, connecting to SQL server from Windows surroundings as well as using CLASSPATH surroundings variable, append the place of sqljdbc4.jar (or the JAR you lot are using) into CLASSPATH every bit set CLASSPATH = %CLASSPATH%; {location of driver jar}. Please notice, separator inward windows is semicolon (;)
6) For Java application connecting to Microsoft SQL Server from UNIX based systems e.g. Linux, include this JAR file into the shape path every bit export CLASSPATH = ${CLASSPATH} : (directory of driver jar}. Please note, the separator inward Linux is a colon(:). BTW, don't acquire confused betwixt using same JAR file inward Windows as well as Linux, Java is platform independent as well as that's why you lot tin role same JAR file inward all platforms. Also, fifty-fifty though MSSQL solely runs on Windows machine, you lot tin even hence connect to it from Linux using Java client.
7) If your Java computer program is using -cp or -classpath selection e.g. java -cp {%LIB%} MyProgram, as well as then brand certain you lot include the JDBC driver appall into the LIB surroundings variable. If you lot are direct providing the JAR similar inward simplest cases role :
coffee -cp .;C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc.jar
8) If you lot are running Java computer program inward Eclipse, brand certain you lot add together sqljdbc41.jar (or whatever JDBC driver JAR) into construct path yesteryear selecting your program, right click, configure construct path.
That's all most how to solve java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inward Java. If you lot are even hence non able to solve the occupation as well as then delight cheque for unlike CLASSPATH related issues every bit shown inward my post service most how CLASSPATH plant inward Java. It's non unlike than solving similar occupation comes piece connecting to Oracle, MySQL, PostgreSQL or whatever other relational database. In most cases, it's merely the missing JAR file which causes the problem. In merely about cases, it's the wrong JAR file as well as inward merely about rare cases, it's those classpath mysteries.
Other classpath related issues which comes when you lot effort to connect database from Java computer program :
Further Learning
JSP, Servlets as well as JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 as well as 2
Java Platform: Working amongst Databases Using JDBC
Similarly, inward Java spider web application JDBC drivers are required to endure nowadays inward WEB-INF/lib directory or if you lot are running on Tomcat as well as then tomcat/lib directory every bit well. Finding solution becomes tardily 1 time you lot know how classpath concept plant inward Java, a must know for whatever Java developer.
Let's effort to discovery out the existent crusade of java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver as well as how to solve this nasty fault which is preventing your Java computer program to connect to Microsoft SQL Server 2008, 2012 or fifty-fifty 2014 database.
By the way, if you lot actually desire to empathise Java database programming from scratch, I advise you lot read the book, Practical database programming amongst Java book yesteryear Ying Bai. This mass explains every of import especial of Java database connectivity as well as JDBC amongst the uncomplicated example.
Which JDBC Driver JAR to use?
In guild to connect to whatever database including SQL Server from Java program, nosotros role JDBC (Java Database Connectivity) API. This API is nowadays inward JDK itself hence you lot don't require whatever additional JAR to role this but because it has to back upwards unlike database vendor, it has provided a Driver interface, which is required for database vendors similar Oracle, MySQL or Microsoft SQL Server to implement, if they desire to allow their database access via JDBC.This Driver implementation shape is a must for connecting to database. If you lot know the piffling fleck of history, at that spot are 4 types of JDBC drivers, but straightaway days almost all database back upwards type 4, pure Java JDBC driver, which comes every bit JAR file as well as quite tardily to use.
All you lot require to produce is include those JAR e.g. mysql-connector.jar for MySQL, ojdbc6.jar for Oracle 11g database as well as sqljdbc4.jar for SQL Server into your Java application's classpath.
Sometimes you lot may discovery that at that spot is fifty-fifty multiple JDBC driver JAR available for the same database e.g. sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar for MSSQL database. This is because of unlike JDBC version available inward unlike JREs.
The latest version of JDBC is JDBC 4.1 released inward Java 7, which is supported yesteryear Microsoft inward sqljdbc41.jar, as well as you lot must role this JAR if you lot are connecting Microsoft SQL Server 2008 or 2012 from Java 1.7 or Java 1.8. If you lot role this JAR amongst JRE version less than 1.7, you lot volition acquire exception e.g. SQLFeatureNotSupportedException.
Similarly, if you lot are connecting to SQL Server database from Java 1.6 as well as then role sqljdbc4.jar, which supports JDBC 4.0 version, using this JAR inward Java 1.5 volition upshot inward Exception. Similarly, if you lot are connecting to MSSQL database from JRE 1.5 as well as then role sqljdbc.jar, which uses JDBC 3.0.
See Core Java Volume II Advanced Features yesteryear Cay S. Horstmann to acquire to a greater extent than most novel JDBC features introduced inward JDBC 3.0 as well as JDBC 4.0 on JDK 7.
com.microsoft.sqlserver.jdbc.SQLServerDriver
In guild to charge the JDBC driver from sqljdbc.jar, Java uses Class.forName() method. This method takes the cite of the shape which implement java.sql.Driver interface as String and tries to charge that shape yesteryear searching into classpath e.g. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").As a upshot of this method telephone band JVM (class loader) volition hold off for a shape com.microsoft.sqlserver.jdbc.SQLServerDriver inward your Java program's classpath. If it doesn't flora the shape it throws "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver".
In total Java, it could endure your uncomplicated Java computer program which is executing this delineate of piece of work as well as inward firm Java, it could endure a web server or firm server or a framework executing this code on your behalf.
How to laid upwards java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
As I said, depending upon private province of affairs solution of this fault could endure piffling different, but this is what you lot should effort :1) Check if you lot receive got downloaded JDBC Driver for Microsoft SQL Server i.e. whatever of sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar, if non as well as then delight download it from hither http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774 as well as add together into CLASSPATH of your Java program.
2) Make certain you lot download the right JDBC driver JAR for SQL SERVER depending upon your Java version e.g. sqljdbc.jar if you lot are connecting to Microsoft SQL server from Java 1.5, sqljdbc4.jar if you lot are running Java 1.6 or sqljdbc41.jar if you lot are using Java 1.7 or Java 8.
3) Make certain you lot solely add together 1 of these JAR, non all or them or fifty-fifty 2 of them.
4) If you lot are connecting to Microsoft SQL Server from Tomcat or whatever firm server e.g. JBoss or Weblogic, as well as then brand certain you lot include MSSQL JDBC driver JAR inward WEB-INF/lib directory. Sometimes, you lot likewise require to add together this into tomcat/lib if at that spot are multiple application which is connecting to SQL Server.
5) For total Java application, connecting to SQL server from Windows surroundings as well as using CLASSPATH surroundings variable, append the place of sqljdbc4.jar (or the JAR you lot are using) into CLASSPATH every bit set CLASSPATH = %CLASSPATH%; {location of driver jar}. Please notice, separator inward windows is semicolon (;)
6) For Java application connecting to Microsoft SQL Server from UNIX based systems e.g. Linux, include this JAR file into the shape path every bit export CLASSPATH = ${CLASSPATH} : (directory of driver jar}. Please note, the separator inward Linux is a colon(:). BTW, don't acquire confused betwixt using same JAR file inward Windows as well as Linux, Java is platform independent as well as that's why you lot tin role same JAR file inward all platforms. Also, fifty-fifty though MSSQL solely runs on Windows machine, you lot tin even hence connect to it from Linux using Java client.
7) If your Java computer program is using -cp or -classpath selection e.g. java -cp {%LIB%} MyProgram, as well as then brand certain you lot include the JDBC driver appall into the LIB surroundings variable. If you lot are direct providing the JAR similar inward simplest cases role :
coffee -cp .;C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc.jar
8) If you lot are running Java computer program inward Eclipse, brand certain you lot add together sqljdbc41.jar (or whatever JDBC driver JAR) into construct path yesteryear selecting your program, right click, configure construct path.
That's all most how to solve java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inward Java. If you lot are even hence non able to solve the occupation as well as then delight cheque for unlike CLASSPATH related issues every bit shown inward my post service most how CLASSPATH plant inward Java. It's non unlike than solving similar occupation comes piece connecting to Oracle, MySQL, PostgreSQL or whatever other relational database. In most cases, it's merely the missing JAR file which causes the problem. In merely about cases, it's the wrong JAR file as well as inward merely about rare cases, it's those classpath mysteries.
Other classpath related issues which comes when you lot effort to connect database from Java computer program :
- How to laid upwards java.lang.ClassNotFoundException: org.postgresql.Driver fault inward Java? [solution]
- General Guide to solve java.lang.ClassNotFoundException inward Java [guide]
- How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver inward Java MySQL? [solution]
- java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
- How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver inward Java? [solution]
- How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
Further Learning
JSP, Servlets as well as JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 as well as 2
Java Platform: Working amongst Databases Using JDBC
![java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [Solution] error comes when you lot effort to connect to Microsoft SQL Server database from Java computer program but java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [Solution]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzGQ9N795NEIpWNK9lw-Vz7oGE0EL0Owqv6zwEf7oHxGdmeIklM_js2Cs4j8DAOLAWPpLSKRWIOsqu1FRcRUgQJSQY7enq3POmye1mkPlLEHjA4E48DcEd8ZcTV6Er-7_c39Bgq6JS0ADB/s320/Practical+Database+Programming.jpg)

![java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [Solution] error comes when you lot effort to connect to Microsoft SQL Server database from Java computer program but java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [Solution]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNunNYa_VSRMSV1KesyHUnyTxCKrxigRyPQj-ejcj7F11c2nWlZ1KQoKJI7BP-soYCgdnc3ReYRJMCzZgSMUAxzxmNcdkxRe_PedxLgkzqJzw4_GearUdAQrh6DLZXw4v2AWP5-JJoXq9e/s640/ClassNotFoundException+while+Connecting+to+SQL+Server+2012+databse+from+Java+program.jpg)
Komentar
Posting Komentar