问题描述
我在我的PC和Mac(netbeans)上有同样的项目。当我试图打开它在我的Mac得到没有合适的驱动程序找到。我使用相同的库/项目。我正在读,我需要在glassfish文件夹中手动添加连接器的库文件?但我不知道在哪里
I have the same project on my PC and Mac (netbeans). When i try to open it on my Mac get "no suitable driver found". I'm using the same library/project on both. I was reading that i need to add the library file for the connector manually inside the glassfish folder? but i dont know where
我得到以下错误:
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)
推荐答案
以下是从SQLServer数据库读取的简单代码。
数据库名称为database1。
表名是table1。
它包含两列uname和pass。
不要忘记向您的项目添加sqljdbc4.jar。
Following is a simple code to read from SQLServer database.Database names is "database1".Table name is "table1".It contain two columns "uname" and "pass".Dont forget to add "sqljdbc4.jar" to your project.
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();
}
}
}
这篇关于java.sql.SQLException:没有为netbeans找到合适的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!