【问题标题】:Hibernate connects to wrong databaseHibernate 连接到错误的数据库
【发布时间】:2012-09-12 16:55:37
【问题描述】:
    <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:jtds:sqlserver://host/:port/db_name;instance=smth</property>
    <property name="hibernate.connection.username">XXX</property>
    <property name="hibernate.connection.password">YYY</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

使用此配置,hibernate 将我的程序连接到“master”数据库而不是“db_name”。我该如何解决这个问题?

编辑:jtds 1.2.5。

【问题讨论】:

  • 只是猜测,你的应用程序真的使用了这个conf吗?你有其他的conf(文件/jndi/spring beans)吗?可能你使用了错误的 conf 名称(maven profile/files/jndi/spring beans..),但继续检查另一个?
  • Kent,它真的很有用,因为如果我在这个 conf 中更改某些内容,它会崩溃/无法连接到服务器。
  • 问题已解决 - SQL Server 的配置方式无法使用名称实例。 jdbc:jtds:sqlserver://host:port/db_name(不带 ;instance=smth)工作正常
  • 请将您的答案添加到答案部分并自行更正

标签: java sql-server hibernate jtds


【解决方案1】:

问题已解决 - SQL Server 的配置方式无法使用名称实例。 jdbc:jtds:sqlserver://host:port/db_name(不带 ;instance=smth)工作正常

【讨论】:

    【解决方案2】:

    您的网址在我看来不正确。不知道是不是笔误,应该是这样的:

    jdbc:jtds:sqlserver://host:port/db_name;instance=smth
    

    主机和端口之间不应有斜线。

    http://jtds.sourceforge.net/faq.html#urlFormat

    【讨论】:

    • 不幸的是,它并没有解决这个问题,没有斜线,hibernate无法连接到服务器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2019-03-01
    相关资源
    最近更新 更多