好的,我很困惑。我的SQL Server JAR是在這裏:Classpath set,但:java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver
Volume in drive C has no label.
Volume Serial Number is 8008-2D93
Directory of c:\temp
03/07/2014 09:38 AM <DIR> .
03/07/2014 09:38 AM <DIR> ..
03/05/2014 10:34 PM 222,417 output.exd
02/17/2012 02:45 PM 563,117 sqljdbc.jar
02/17/2012 02:45 PM 584,207 sqljdbc4.jar
3 File(s) 1,369,741 bytes
2 Dir(s) 21,865,553,920 bytes free
我的類路徑設置:
C:\WINDOWS\system32>echo %CLASSPATH%
.;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;c:\temp\sqljdbc4.jar
它是一個JDBC 4.0驅動程序,所以我不應該要做到這一點,但我已經嘗試設置類名稱。
Properties connectionProps = new Properties();
connectionProps.put("user", this.jdbcUser);
connectionProps.put("password", this.jdbcPass);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(this.jdbcUrl, connectionProps);
還是我執行我的計劃,我得到的錯誤:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
C:\WINDOWS\system32>java -jar "C:\Users\MYUSER\Documents\NetBeansProjects\myappSource\dist\myappSource.jar" -u MYUSER -p MYPASS -j "jdbc:sqlserver://127.0.0.1\\msqlserver:1433;database=MYDB"
Mar 07, 2014 9:49:54 AM filters.myapp.dao.db.DbSwitcher getDatabaseForUrl
SEVERE: jdbc:sqlserver://127.0.0.1\\msqlserver:1433;database=MYDB
Mar 07, 2014 9:49:54 AM filters.myapp.dao.db.Database connect
SEVERE: null
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
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)
at filters.myapp.dao.db.Database.connect(Database.java:217)
at filters.myapp.dao.db.Database.<init>(Database.java:38)
at filters.myapp.dao.db.MssqlDb.<init>(MssqlDb.java:15)
at filters.myapp.dao.db.DbSwitcher.getDatabaseForUrl(DbSwitcher.java:14)
at filters.myapp.UserInterface.cli(UserInterface.java:76)
at filters.myapp.UserInterface.<init>(UserInterface.java:34)
at filters.myapp.UserInterface.main(UserInterface.java:46)
如果它的事項,我運行Windows 8.1。我已經嘗試了命令提示符作爲管理員和不。
Java的信息:
C:\WINDOWS\system32>java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
任何想法?
SQL Server是SQL Server Express的2012
這看起來很有希望。我正在嘗試選項#1。 – Doug
就是這樣,謝謝你! – Doug