添加jar包的方法
- 右键工程 --> Build Path --> Configure Build Path
- 进入界面后,Libraries --> Class Path --> Add External JARs…
- 选择要导入的jar包 --> Apply and Close
错误1
无法创建驱动程式实体!java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433; DatabaseName=MyMoney
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at mymoney.Login.initializeDB(Login.java:125)
at mymoney.Login.(Login.java:39)
at mymoney.Login$6.run(Login.java:293)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue 4. r u n ( E v e n t Q u e u e . j a v a : 715 ) a t j a v a . b a s e / j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( A c c e s s C o n t r o l l e r . j a v a : 391 ) a t j a v a . b a s e / j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) at java.base/java.security.ProtectionDomain 4.run(EventQueue.java:715)atjava.base/java.security.AccessController.doPrivileged(AccessController.java:391)atjava.base/java.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
解决方案
导入 sqljdbc4-chs-4.0.2206.100.jar包 (驱动sql包)