【问题标题】:Using Oracle, suddenly receiving ORA-12154 TNS: could not resolve message使用 Oracle,突然收到 ORA-12154 TNS: could not resolve message
【发布时间】:2016-05-03 16:36:20
【问题描述】:

我正在使用 PL/SQL Developer 完美地连接到 Oracle 数据库。我试图从我的 java 代码中访问数据库。之后我收到了来自 PL/SQL Developer 的错误“ORA-12154 TNS: could not resolve”;我仍然可以通过我的代码访问数据库并对其进行查询。

我已阅读此错误的建议解决方案,但由于我在 Windows 和数据库服务器上使用具有有限权限的瘦客户端(我只能对其进行查询!!),我无法使用它们。

感谢任何解决此问题的建议。

我也很好奇这个问题的原因,因为在我运行我的代码之前一切都很好;这就像连接到数据库并查询我有权访问的一个视图一样简单!!! 请注意,其他瘦客户端上的其他用户也无法与 PL/SQL Developer 连接。 我的代码如下:

 public static void main(String[] args) throws IOException {
    // TODO code application logic here

   Logger logger = Logger.getLogger("MyLog");
    FileHandler fh;
    fh = new FileHandler("C:/Users/batam/Documents/MyLogFile.log");
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);

        Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection connection = null;

    try {
        connection = DriverManager.getConnection(
                "jdbc:oracle:thin:@capmtr10:1521/FINDATA1", "bamat",
                "fg_3002");

    } catch (SQLException e) {

              e.printStackTrace();

        return;

    }

    if (connection != null) {

        try {
            String sql = "select a.userid, a.Description from USER_FINANCE a where a.userid = 'batam'";

            Statement stmt = connection.createStatement();

            ResultSet rs = stmt.executeQuery(sql);

            while (rs.next()) {

                String id = rs.getString("userid");
                String name = rs.getString("Description");

                logger.info("Selecteds are : " + id + " : " + name);
            }

            rs.close();
            stmt.close();
        } catch (SQLException e) {
            logger.info("SQLException : " + e.getMessage());
        } finally {
            try {
                connection.close();
            } catch (SQLException ex) {
                Logger.getLogger(IFS.class.getName()).log(Level.SEVERE, null, ex);
                logger.info("Close Exception : " + ex.getMessage());
            }
        }

    } else {
        System.out.println("Failed to make connection!");
        logger.info("Failed to make connection!");
    }

}

我已使用 system_context 函数从我的瘦客户端上的 PL/SQL 开发人员那里检索到服务器主机名和服务名,而它仍在连接而没有出现此错误。

提前谢谢你。

【问题讨论】:

  • 向我们展示导致异常的代码。
  • PL/SQL 不是访问 Oracle 的工具。您使用的工具的真实名称是什么? PL/SQL 开发人员? SQL加? SQL开发者?蟾蜍?
  • 你在 Java 中使用什么连接字符串?您在其他工具中指定了哪些连接设置?
  • 亲爱的,我已将您的问题的答案添加到我的问题主体中
  • PL/SQL Developer 使用安装文件夹时会出现错误。如果您将它安装在程序文件 (x86) 文件夹下,它将无法解析 TNS 侦听器。不知道他们修好了没有。这很烦人。值得检查

标签: sql oracle jdbc


【解决方案1】:

您是否安装了 oracle 客户端工具?如果是这样,在 cmd 上 tnsping YOUR_SID 将为您提供与数据库的连接状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-17
    • 2016-04-26
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 2014-12-17
    相关资源
    最近更新 更多