Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java JDBC Oracle JDK 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
 
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 22-Oct-12 11:28am
Edited 23-Oct-12 3:25am
Nagy Vilmos275.1K
v2
Comments
Nagy Vilmos at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 23 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100