0
我可以從我的虛擬操作系統(Windows 8)在我的Mac上連接到sqlserver,但是我無法連接到mac上的sqlserver。如何在OS X上使用jTDS驅動程序連接到SQL Server?
我的連接字符串如下所示。
server = (String) modelmain.getProp().getProperty("testserver1");
db = (String) modelmain.getProp().getProperty("testdb1");
user = (String) modelmain.getProp().getProperty("testuser1");
pass = (String) modelmain.getProp().getProperty("testpass1");
String getDatabaseJtdsUrl = "jdbc:jtds:sqlserver://" + server + "/" + db + ";";
我的變量如下所示。
server = "MyServer:1433"
db= "Mydb"
user = "dbuser"
pass = "userpassword"
我給用戶名和通過hibernate的屬性方法。順便說一下,我使用休眠。
Configuration cfg = new Configuration();
cfg.setProperty("hibernate.connection.driver_class",
"net.sourceforge.jtds.jdbc.Driver");
cfg.setProperty("hibernate.connection.url", getDatabaseJtdsUrl);
cfg.setProperty("hibernate.connection.username", user);
cfg.setProperty("hibernate.connection.password", pass);
如何在mac osx上使用jtds驅動程序連接到sqlserver?
錯誤在下面。
SessionFactory initial creation error.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Exception in thread "Thread-1" java.lang.ExceptionInInitializerError
at com.ozpas.dao.HibernateUtilOzpasentegre.<clinit>(HibernateUtilOzpasentegre.java:75)
at com.ozpas.entegre.model.ModelConfig.prepareMapconfig(ModelConfig.java:41)
at com.ozpas.entegre.model.ModelConfig.<init>(ModelConfig.java:23)
at com.ozpas.entegre.model.ModelConfig.getInstance(ModelConfig.java:29)
at com.ozpas.dao.ConnectionFactoryMikro.<init>(ConnectionFactoryMikro.java:20)
at com.ozpas.dao.ConnectionFactoryMikro.<clinit>(ConnectionFactoryMikro.java:15)
at com.ozpas.entegre.model.ModelCari.getlistCarileruppercase(ModelCari.java:1584)
at com.ozpas.entegre.model.ModelCachevar.prepareCachemusteribilgileri(ModelCachevar.java:39)
at com.ozpas.entegre.controller.MainCr$2.run(MainCr.java:88)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at com.ozpas.dao.HibernateUtilOzpasentegre.<clinit>(HibernateUtilOzpasentegre.java:70)
... 8 more
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:115)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:101)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:123)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:41)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:58)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.addConnections(PooledConnections.java:106)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:40)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:19)
at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:138)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:110)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:74)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
... 22 more
Caused by: java.sql.SQLException: Unknown server host name 'MYSERVER'.
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:427)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:38)
... 37 more
Caused by: java.net.UnknownHostException: MYSERVER
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
...
39 more
我沒有添加實體在我的問題中的類代碼,因爲它不是那麼需要表達它們。我想讓問題簡潔。實際上,在我的應用程序中,實體類被添加到配置中。有趣的是,應用程序在Windows 8上工作,但由於連接特定的問題,它不適用於mac ocx。 – bmtncy