ora 12505错误监听器拒绝连接

时间:2012-10-22 20:20:37

标签: java oracle jdbc oracle10g odbc

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。 我正在使用Java 7,我的tnsname.ora也包含(PORT = 1521)) 所以我无法理解给定的错误。

2 个答案:

答案 0 :(得分:1)

您的数据库网址错误。它应该是: jdbc:oracle:thin:@localhost:1521 / XE< - 对于SID值,请注意斜杠而不是冒号(在您的情况下为“XE”)

答案 1 :(得分:0)

oracle documentation您的连接字符串应具有以下格式:

jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename