<tfoot id='vxbEw'></tfoot>
  1. <i id='vxbEw'><tr id='vxbEw'><dt id='vxbEw'><q id='vxbEw'><span id='vxbEw'><b id='vxbEw'><form id='vxbEw'><ins id='vxbEw'></ins><ul id='vxbEw'></ul><sub id='vxbEw'></sub></form><legend id='vxbEw'></legend><bdo id='vxbEw'><pre id='vxbEw'><center id='vxbEw'></center></pre></bdo></b><th id='vxbEw'></th></span></q></dt></tr></i><div id='vxbEw'><tfoot id='vxbEw'></tfoot><dl id='vxbEw'><fieldset id='vxbEw'></fieldset></dl></div>

    <small id='vxbEw'></small><noframes id='vxbEw'>

    <legend id='vxbEw'><style id='vxbEw'><dir id='vxbEw'><q id='vxbEw'></q></dir></style></legend>

      • <bdo id='vxbEw'></bdo><ul id='vxbEw'></ul>

      如何获取 SQL 连接的默认模式?

      时间:2023-09-30
    1. <small id='Qoihz'></small><noframes id='Qoihz'>

        <tfoot id='Qoihz'></tfoot>
            <tbody id='Qoihz'></tbody>

          <legend id='Qoihz'><style id='Qoihz'><dir id='Qoihz'><q id='Qoihz'></q></dir></style></legend>

            • <bdo id='Qoihz'></bdo><ul id='Qoihz'></ul>
              <i id='Qoihz'><tr id='Qoihz'><dt id='Qoihz'><q id='Qoihz'><span id='Qoihz'><b id='Qoihz'><form id='Qoihz'><ins id='Qoihz'></ins><ul id='Qoihz'></ul><sub id='Qoihz'></sub></form><legend id='Qoihz'></legend><bdo id='Qoihz'><pre id='Qoihz'><center id='Qoihz'></center></pre></bdo></b><th id='Qoihz'></th></span></q></dt></tr></i><div id='Qoihz'><tfoot id='Qoihz'></tfoot><dl id='Qoihz'><fieldset id='Qoihz'></fieldset></dl></div>
                本文介绍了如何获取 SQL 连接的默认模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                从 java 代码中 - 我已经连接到数据库 - 我需要找到连接的默认模式.

                From within a java code - where I already have a connection to a database - I need to find the default schema of the connection.

                我有以下代码,它为我提供了该连接的所有模式的列表.

                I have the following code that gives me a list of all schemas of that connection.

                rs  = transactionManager.getDataSource().getConnection().getMetaData().getSchemas();
                while (rs.next()) {
                    log.debug("The schema is {} and the catalogue is {} ", rs.getString(1), rs.getString(2));
                }
                

                但是,我不想要所有模式的列表.我需要此连接的默认架构.

                However, I don't want the list of all the schemas. I need the default schema of this connection.

                请帮忙.

                注意 1:我在 Windows7(开发盒)和 Linux Redhat(生产盒)上使用 H2 和 DB2

                Note1: I am using H2 and DB2 on Windows7 (dev box) and Linux Redhat (production box)

                注2:我最终得出结论,使用Java 中的Connections 对象无法使用相同的代码找到H2 和DB2 的默认模式.我用配置文件解决了这个问题.但是,如果有人可以分享解决方案,我可以回去重构代码.

                Note2: I finally concluded that it was not possible to use the Connections object in Java to find the default schema of both H2 and DB2 using the same code. I fixed the problem with a configuration file. However, if someone can share a solution, I could go back and refactor the code.

                推荐答案

                请使用 connection.getMetaData().getURL() 方法,该方法返回类似字符串的方法

                Please use connection.getMetaData().getURL() method which returns String like

                jdbc:mysql://localhost:3306/?autoReconnect=true&useUnicode=true&characterEncoding=utf8
                

                我们可以轻松解析它并获取架构名称.它适用于所有 JDBC 驱动程序.

                We can parse it easily and get the schema name. It works for all JDBC drivers.

                这篇关于如何获取 SQL 连接的默认模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:多次搜索导致 OutOfMemoryError 下一篇:如何修复错误“java.lang.ClassNotFoundException: sun.io

                相关文章

                最新文章

                <legend id='OuZry'><style id='OuZry'><dir id='OuZry'><q id='OuZry'></q></dir></style></legend>
                    <bdo id='OuZry'></bdo><ul id='OuZry'></ul>
                  <tfoot id='OuZry'></tfoot>

                  1. <i id='OuZry'><tr id='OuZry'><dt id='OuZry'><q id='OuZry'><span id='OuZry'><b id='OuZry'><form id='OuZry'><ins id='OuZry'></ins><ul id='OuZry'></ul><sub id='OuZry'></sub></form><legend id='OuZry'></legend><bdo id='OuZry'><pre id='OuZry'><center id='OuZry'></center></pre></bdo></b><th id='OuZry'></th></span></q></dt></tr></i><div id='OuZry'><tfoot id='OuZry'></tfoot><dl id='OuZry'><fieldset id='OuZry'></fieldset></dl></div>

                  2. <small id='OuZry'></small><noframes id='OuZry'>