我正在尝试使用JDBC连接到SQL Server 2008。我的SQL Server 2008带有Windows身份验证。
我的代码是
public class T1 { /** * @param args */ private static void Connect(){ try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String connectionUrl = "jdbc:sqlserver://servername;databaseName=employee;user=username;password=''/*since it is windows authentication*/;"; java.sql.Connection con = DriverManager.getConnection(connectionUrl); } catch(ClassNotFoundException e) { e.printStackTrace(); } catch(SQLException e2) { e2.printStackTrace(); } } public static void main(String[] args) { // TODO Auto-generated method stub T1.Connect(); }
我最终得到ClassNotFoundException。
堆栈跟踪为 java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)
ClassNotFoundException可能意味着您的类路径中没有可用的SQL * Server驱动程序