2012-03-08 109 views
0

我的PC和Mac上有相同的項目(netbeans)。當我嘗試在我的Mac上打開它時,得到「找不到合適的驅動程序」。我在兩個版本上都使用相同的庫/項目。我正在閱讀,我需要在glassfish文件夾中手動添加連接器的庫文件?但我不知道在哪裏java.sql.SQLException:找不到適合netbeans的驅動程序

我得到以下錯誤:

SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.Configure(Database.java:50) 
    at Core.Configuration.Configure(Configuration.java:61) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database InsertSimulation 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.InsertSimulation(Database.java:159) 
    at Core.Configuration.Configure(Configuration.java:62) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadCurrentSimulation 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadCurrentSimulation(Database.java:266) 
    at Core.Configuration.Configure(Configuration.java:63) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadCurrentConfiguration 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadCurrentConfiguration(Database.java:178) 
    at Core.Configuration.ReadCurrentConfiguration(Configuration.java:237) 
    at Core.Configuration.Configure(Configuration.java:64) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadCurrentConfigAsString 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadCurrentConfigAsString(Database.java:311) 
    at Core.Configuration.ReadConfigFromDB(Configuration.java:172) 
    at Core.Configuration.CompareConfig(Configuration.java:203) 
    at Core.Configuration.Configure(Configuration.java:66) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database InsertConfiguration 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.InsertConfiguration(Database.java:105) 
    at Core.Configuration.InsertConfig(Configuration.java:225) 
    at Core.Configuration.Configure(Configuration.java:68) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadCurrentConfiguration 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadCurrentConfiguration(Database.java:178) 
    at Core.Configuration.ReadCurrentConfiguration(Configuration.java:237) 
    at Core.Configuration.Configure(Configuration.java:69) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadEssentialAppliances 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadEssentialAppliances(Database.java:408) 
    at Core.Configuration.ReadEssentialAppliances(Configuration.java:115) 
    at Core.Configuration.Configure(Configuration.java:71) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database ReadNonEssentialAppliances 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadNonEssentialAppliances(Database.java:356) 
    at Core.Configuration.ReadNonEssentialAppliances(Configuration.java:144) 
    at Core.Configuration.Configure(Configuration.java:72) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:51) 
Mar 8, 2012 5:30:43 PM Database.Database InsertHome 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.InsertHome(Database.java:90) 
    at Core.SmartHome.InsertSmartHome(SmartHome.java:34) 
    at Core.SmartHome.<init>(SmartHome.java:28) 
    at Core.Processor.CreateHomes(Processor.java:65) 
    at Core.Processor.Start(Processor.java:43) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:52) 
Mar 8, 2012 5:30:43 PM Database.Database ReadCurrentHome 
SEVERE: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.ReadCurrentHome(Database.java:222) 
    at Core.SmartHome.InsertSmartHome(SmartHome.java:35) 
    at Core.SmartHome.<init>(SmartHome.java:28) 
    at Core.Processor.CreateHomes(Processor.java:65) 
    at Core.Processor.Start(Processor.java:43) 
    at desktopapplication2.DesktopApplication2.main(DesktopApplication2.java:52) 
Mar 8, 2012 5:30:45 PM Database.Database databaseDataReturn 
WARNING: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.databaseDataReturn(Database.java:459) 
    at desktopapplication2.DesktopApplication2View.<init>(DesktopApplication2View.java:68) 
    at desktopapplication2.DesktopApplication2.startup(DesktopApplication2.java:25) 
    at org.jdesktop.application.Application$1.run(Application.java:171) 
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:677) 
    at java.awt.EventQueue.access$000(EventQueue.java:85) 
    at java.awt.EventQueue$1.run(EventQueue.java:638) 
    at java.awt.EventQueue$1.run(EventQueue.java:636) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:647) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 
Mar 8, 2012 5:30:45 PM Database.Database databaseDataReturn 
WARNING: No suitable driver found for 
java.sql.SQLException: No suitable driver found for 
    at java.sql.DriverManager.getConnection(DriverManager.java:602) 
    at java.sql.DriverManager.getConnection(DriverManager.java:185) 
    at Database.Database.databaseDataReturn(Database.java:459) 
    at desktopapplication2.DesktopApplication2View.<init>(DesktopApplication2View.java:75) 
    at desktopapplication2.DesktopApplication2.startup(DesktopApplication2.java:25) 
    at org.jdesktop.application.Application$1.run(Application.java:171) 
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:677) 
    at java.awt.EventQueue.access$000(EventQueue.java:85) 
    at java.awt.EventQueue$1.run(EventQueue.java:638) 
    at java.awt.EventQueue$1.run(EventQueue.java:636) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:647) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 
BUILD SUCCESSFUL (total time: 4 seconds) 
+0

您的項目lib是否需要jar? – kosa 2012-03-08 17:39:39

+0

是的,我添加它。但我已經閱讀了一些地方,它可能無法檢測到它運行時,我需要將它放在另一個文件夾而不是導入它。我不知道在哪裏? – 2012-03-08 17:58:10

+0

它將是服務器的ext文件夾 – kosa 2012-03-08 18:55:35

回答

0

下面是一個簡單的代碼從SQLServer數據庫讀取。 數據庫名稱是「database1」。 表名是「table1」。它包含兩列「uname」和「pass」。 不要忘記添加「sqljdbc4.jar」到您的項目。

public class NewClass { 

    public static void main(String[] args) { 

     Connection conn = null; 
     String dbName = "database1"; 
     String serverip="192.168.100.100"; 
     String serverport="1433"; 
     String url = "jdbc:sqlserver://"+serverip+"\\SQLEXPRESS:"+serverport+";databaseName="+dbName+""; 
     Statement stmt = null; 
     ResultSet result = null; 
     String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; 
     String databaseUserName = "admin"; 
     String databasePassword = "root"; 
     try { 
      Class.forName(driver).newInstance(); 
      conn = DriverManager.getConnection(url, databaseUserName, databasePassword); 
      stmt = conn.createStatement(); 
      result = null; 
      String pa,us; 
      result = stmt.executeQuery("select * from table1 "); 

      while (result.next()) { 
       us=result.getString("uname"); 
       pa = result.getString("pass");    
       System.out.println(us+" "+pa); 
      } 

      conn.close(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
相關問題