java.sql.SQLException: не найден подходящий драйвер для сетевых компонентов - PullRequest
0 голосов
/ 08 марта 2012

У меня один и тот же проект на моем ПК и 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 голосов
/ 27 июня 2012

Ниже приведен простой код для чтения из базы данных 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();
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...