我有一台MySQL服务器只接受管道连接。
这是我的my.ini的摘录:
[client]
pipe
socket=mysql
[mysql]
default-character-set=utf8
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
skip-networking
enable-named-pipe我的客户端MySqlWorkbench设法通过命名管道连接,并通过TCP / IP失败,这是预期的行为。
我的问题是我的Java Swing应用程序无法连接。它使用Spring 3和Hibernate 3.2。我使用的是Windows 2003服务器,MySQL版本是5.5。
这里是我的Spring beans:
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
entries.hbm.xml
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.url=jdbc:mysql://localhost/catalog
hibernate.connection.username=root
hibernate.connection.password=root
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.jdbc.batch_size=0
hibernate.connection.socketFactory=com.mysql.jdbc.NamedPipeSocketFactory
在前一版本中,我也使用了dbcp commons,但遇到同样的问题,为了缩小范围,我删除了它。
我可以让事情在TCP / IP中工作,但我想使用命名管道。
根据文档,为了让客户端使用管道,您需要指定namedPipeFactory,并且不要在URL中指定端口号。
我继续研究,发现如果我这样做:
Class.forName("com.mysql.jdbc.Driver");
Connection connexion = DriverManager.getConnection("jdbc:mysql:///catalogue?socketFactory=com.mysql.jdbc.NamedPipeSocketFactory","root", "root");然后它工作。
这意味着Spring看起来并没有加载我的hibernate.properties,这很奇怪,因为当我查看Spring启动时使用的属性时,我的休眠属性确实出现了。
出现以下日志行:
DEBUG org.hibernate.impl.SessionFactoryImpl - 使用属性实例化会话工厂:
其中一个属性是hibernate.connection.url = jdbc:mysql:/// catalog?socketFactory = NamedPipeSocketFactory
我明确地不明白发生了什么事....
那么我做错了什么?
非常感谢 !