java.sql.SQLException:找不到适合netbeans的驱动程序

时间:2012-03-08 17:34:13

标签: java sql database netbeans

我的PC和Mac(netbeans)上有相同的项目。当我尝试在我的Mac上打开它时,“找不到合适的驱动程序”。我在两者上使用相同的库/项目。我正在阅读我需要在glassfish文件夹中手动添加连接器的库文件?但我不知道在哪里

我收到以下错误:

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)

1 个答案:

答案 0 :(得分: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();
        }
    }
}