Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
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


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.
Posted
Updated 23-Oct-12 2:25am
v2
Comments
Nagy Vilmos 23-Oct-12 8:26am    
Txtspk will get you no where here. The clearer the language we use, the easier it is for others to understand and help.

1 solution

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=
      ...))


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900