找不到Java Oracle连接错误(ORA-12505)sid [英] Java Oracle connection error (ORA-12505) sid not found

查看:656
本文介绍了找不到Java Oracle连接错误(ORA-12505)sid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.util.*;
import java.io.*;
import java.sql.*;
public class Stud
{
   public static void main(String args[])
   {
      try
      {
         Class.forName("oracle.jdbc.driver.OracleDriver");
         System.out.println("Driver Registered");
         Connection connection =
               DriverManager.getConnection(
                     "jdbc:oracle:thin:@localhost:1521:XE","bh","1234");
         System.out.println("Connection created");
         PreparedStatement ps =
               connection.prepareStatement(
                     "insert into Student" +
                     " (StudName,dob,math,phy,chem,agg)" +
                     " values (?,?,?,?,?,?)");
         System.out.println("prepare stmt ");
         ps.setString(1,"name");
         ps.setString(2,"dob");
         ps.setInt(3,96);
         ps.setInt(4,96);
         ps.setInt(5,94);
         ps.setDouble(6,96);
         int a=ps.executeUpdate();
         ps.close();
         connection.close();
      }
      catch(Exception ex) {
         ex.printStackTrace();
      }
   }
}





java.sql.sql exception listner refused to connect with the following error ora 12505 the listner currently does not know of sid in give connectoin descriptor local host 1521



我正在使用Oracle 10 g,并且已在类路径中设置了ojdbc14.jar.我正在使用java7,我的tnsname.ora也包含(PORT = 1521)),所以我无法理解给定的错误.



I am using Oracle 10 g and I have set the ojdbc14.jar in my class path. I am using java7 and my tnsname.ora also contain (PORT = 1521)) so I cant''t understand the given error.

推荐答案

config的重要出价位于listener.ora,需要在其中设置SID;请注意,这不一定是服务名称.
应该是这样的:

The important bid of config is in listener.ora, where you need to set the SID; note that this is not necessarily the service name.
There should be something like:

SID_LIST_LISTENER=
  (SID_LIST=
    (SID_DESC=
      (GLOBAL_DBNAME=foo.bar.com)
      (ORACLE_HOME=/oracle10g)
      (SID_NAME=foo_bar))
    (SID_DESC=
      ...))



更改代码以使用正确的SID(在示例中为foo_bar),或者将您的SID添加到listener.ora并在服务器上重新启动侦听器.



Either change your code to use the correct SID - in the example it is foo_bar - or add your SID to listener.ora and restart the listener on the server.


这篇关于找不到Java Oracle连接错误(ORA-12505)sid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆