Message: ORA-12570: TNS:packet reader failure

Hi,

when i execute the below program,getting "Message: ORA-12570: TNS:packet reader failure" error. java version is 1.3.1 and oracle

version is :9.1.

able to connect to database using sql plus with the same user-id and

password.

Any help in this regard is appreciated.

Thanks

Chat

import java.sql.*;

import java.io.*;

import java.util.Date;

class JdbcTest

{

publicstaticvoid main (String args [])

{

System.out.println ("Loading Oracle driver");

try

{

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

System.out.println ("Connecting to the local database");

Connection conn =

DriverManager.getConnection("jdbc:oracle:oci8:@orcl,scott,tiger");

System.out.println("debug 1 ....\n");

Statement stmt = conn.createStatement ();

System.out.println("debug 2 ....\n");

// Query the employee names

ResultSet rset = stmt.executeQuery ("select ename from emp");

while (rset.next ())

{

// Print the name out

System.out.println (rset.getString (1));

}

}catch (ClassNotFoundException cnfe){

System.out.println ("Could not load the driver");

cnfe.printStackTrace ();

}catch (SQLException sqle){

System.out.println("State : " + sqle.getSQLState() ) ;

System.out.println("Message: " + sqle.getMessage()) ;

System.out.println("Error : " + sqle.getErrorCode() ) ;

}catch (Exception e){

System.out.println ("Could not load the driver");

e.printStackTrace ();

}

}

}

C:\mjava>java JdbcTest

Loading Oracle driver

Connecting to the local database

State : 66000

Message: ORA-12570: TNS:packet reader failure

Error : 12570

C:\mjava>

[3024 byte] By [Chatfielda] at [2007-10-2 15:21:56]
# 1

Hi Chat,

You are using the oci8 driver and you may or may not be aware that oci8 is a type 3 driver that requires that the Oracle client be installed on the computer that is running the Java program. It also requires that you setup Oracle networking correctly, usually by putting an entry into your Oracle tnsnames.ora file.

If there is no reason in particular that you are using the oci8 driver, then you should use the thin driver instead. The thin driver is a type 4 driver and does not require the Oracle client to be installed, and does not require configuration of Oracle networking. You do have to download the Oracle JDBC drivers from the Oracle website to the computer you are going to run your program on, and then place the oracle .jar files that contain the driver into the programs CLASSPATH. This can be done by setting an environment variable or by passing it to java.exe as a command line parameter. The url for the thin driver looks something like this, but you should check the Oracle doc for specifics or search this forum for more examples:

jdbc:oracle:thin:@myserver:1521:mydatabase

When using a type 3 driver you should verify that you have Oracle networking properly configured for the computer that will be running your Java program by either connecting to the database using SQL/Plus or 'ping' the database using Oracle's tnsping utility. Make sure you check for valid connectivity before trying to run your Java program.

WorkForFooda at 2007-7-13 14:32:36 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...