?
Solved

java.sql.SQLException: Io exception: Got minus one from a read call

Posted on 2009-05-18
21
Medium Priority
?
6,666 Views
Last Modified: 2012-06-27
Hi Experts,
                  I am trying to insert some data in the Oracle 10g tables using java.
                 I am getting the following error:

              java.sql.SQLException: Io exception: Got minus one from a read call
     
                 Can someone please tell me, when we get this error?
0
Comment
Question by:aman0711
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 5
  • +4
21 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24412858
Can you post your code, together with the exact stack trace?
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24412893
I've seen that when having a network or firewall issues. As CEHJ suggests, the stack trace will give more info. That error is usually indicative of a lower level socket error code, however, not a SQL error.
0
 
LVL 10

Author Comment

by:aman0711
ID: 24412916
Hi Charles, mrjoltcola,

          here is the stack trace

java.sql.SQLException: Io exception: Got minus one from a read call
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
	at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3695)
	at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
	at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:362)
	at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:536)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:328)
	at java.sql.DriverManager.getConnection(DriverManager.java:572)
	at java.sql.DriverManager.getConnection(DriverManager.java:196)
	at com.summary.Txn_Measurement.loadSummaryTable(Txn_Measurement.java:194)
	at com.summary.Txn_Measurement.print(Txn_Measurement.java:179)
	at com.summary.Summary.print(Summary.java:34)
	at com.summary.DigesterSummary.main(DigesterSummary.java:60)

Open in new window

0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 600 total points
ID: 24412933
Make sure you're using the latest greatest driver
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 600 total points
ID: 24412962
btw is that the first time in the app that you attempt to do a read? Have you read successfully earlier?
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 800 total points
ID: 24412994
It looks like it is happening when you try to connect (getConnection) so it appears to be a firewall issue.

Can you ping the db host from the web app box, or at least "telnet dbhost 1521"?
Can you install the Oracle client so you can verify at the TNS level with tnsping?
0
 
LVL 10

Author Comment

by:aman0711
ID: 24413021
Hi seniors,
     
       This is not a webapp...just a simple java code. Infact I am not even rading anything.. Just a plain insert statement in the code.

       I have oracle client installed on my machine.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24413059
>>Infact I am not even rading anything.. Just a plain insert statement in the code.

OK. Is it the first time you try to do *anything* that you get this error?
0
 
LVL 10

Author Comment

by:aman0711
ID: 24413096
Yes Charles, I have inserted data in the past, but this is the first time I saw this message,
0
 
LVL 10

Author Comment

by:aman0711
ID: 24413126
This is the code

package com.summary;
 
import java.util.*;
import java.sql.*;
 
//import java.util.Iterator;
 
public class TX1 {
 
	private String ag1;
 
	private String sl1;
 
	private String datetime;
 
	private String t1;
 
	private String ag1_inst;
 
	private String p1;
 
	//private HashMap txns= new HashMap();
	private List txns = new ArrayList();
 
	private List txnError = new ArrayList();
 
	/**
	 * @return the ag1
	 */
	public String toString() {
 
		StringBuffer sb = new StringBuffer();
		sb.append(ag1 + "\t");
		sb.append(sl1 + "\t");
		sb.append(datetime + "\t " + t1 + "\t " + ag1_inst + "\t");
		sb.append(p1 + "\n");
		return sb.toString();
	}
 
	public String getag1() {
		return ag1;
	}
 
	/**
	 * @param ag1 the ag1 to set
	 */
	public void setag1(String ag1) {
		this.ag1 = ag1;
	}
 
	/**
	 * @return the sl1
	 */
	public String getsl1() {
		return sl1;
	}
 
	/**
	 * @param sl1 the sl1 to set
	 */
	public void setsl1(String sl1) {
		this.sl1 = sl1;
	}
 
	/**
	 * @return the datetime
	 */
	public String getDatetime() {
		return datetime;
	}
 
	/**
	 * @param datetime the datetime to set
	 */
	public void setDatetime(String datetime) {
		this.datetime = datetime;
	}
 
	/**
	 * @return the t1
	 */
	public String gett1() {
		return t1;
	}
 
	/**
	 * @param t1 the t1 to set
	 */
	public void sett1(String t1) {
		this.t1 = t1;
	}
 
	/**
	 * @return the ag1_inst
	 */
	public String getag1_inst() {
		return ag1_inst;
	}
 
	/**
	 * @param ag1_inst the ag1_inst to set
	 */
	public void setag1_inst(String ag1_inst) {
		this.ag1_inst = ag1_inst;
	}
 
	/**
	 * @return the p1
	 */
	public String getp1() {
		return p1;
	}
 
	/**
	 * @param p1 the p1 to set
	 */
	public void setp1(String p1) {
		this.p1 = p1;
	}
 
	public void addtxns(Txn_Summary txns) {
 
		// System.out.println(txns.toString());
		txns.add(txns);
	}
 
	public void addTxnError(Txn_Error txnerr) {
 
		// System.out.println(txns.toString());
		txnError.add(txnerr);
	}
 
	public void print() {
		//System.out.println( "------------------------------------------------------------------------------" );
		HashMap sdata = new HashMap();
 
		sdata.put("ag1", ag1);
		sdata.put("sl1", sl1);
		sdata.put("datetime", datetime);
		sdata.put("t1", t1);
		sdata.put("ag1_inst", ag1_inst);
		sdata.put("p1", p1);
 
		/*
		 System.out.print(  ag1 + "\t");
		 System.out.print(  sl1 + "\t");
		 System.out.print( datetime + "\t " + t1 + "\t " + ag1_inst + "\t");
		 System.out.print( p1 + "\t"); */
 
		for (Iterator i = txns.iterator(); i.hasNext();) {
			tnx_s tnx_s = (tnx_s) i.next();
			//tnx_s.print();
 
			sdata.put("d_ms", tnx_s.getd_ms());
			sdata.put("d_u_m", tnx_s.getd_u_m());
			sdata.put("con_e", tnx_s.getcon_e());
 
		}
 
		for (Iterator i = txnError.iterator(); i.hasNext();) {
			Txn_Error error = (Txn_Error) i.next();
			//error.getCode();
			sdata.put("code", error.getCode());
			sdata.put("page", error.getPage());
 
			//System.out.print( error.getCode() + "\t");
 
			//System.out.print( error.getPage() +"\n");
			//error.print();
		}
		loadSummaryTable(sdata);
		//System.out.println( "\n------------------------------------------------------------------------------" );
	}
 
	private void loadSummaryTable(HashMap summaryData) {
		String Sql = "";
 
		String url = "jdbc:oracle:thin:@abc.xyz.com:1522;
		String user = "png11";
		String pass = "png123";
 
		Connection conn = null;
 
		try {
			Class.forName("oracle.jdbc.OracleDriver").newInstance();
			conn = DriverManager.getConnection(url, user, pass);
 
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
		System.out.print(summaryData.get("ag1") + "\t");
		System.out.print(summaryData.get("sl1") + "\t");
		System.out.print(summaryData.get("datetime") + "\t");
		System.out.print(summaryData.get("t1") + "\t");
		System.out.print(summaryData.get("ag1_inst") + "\t");
		System.out.print(summaryData.get("p1") + "\n");
 
		try {
 
			//System.out.println( conn );
			PreparedStatement pstmt = null;
 
			Sql = "insert into png.knsummary (ag1, sl1, DATETIME, t1, ag1_INST, p1, d_ms, d_u_m, con_e) values (?,?,?,?,?,?,?,?,?)";
 
			pstmt = conn.prepareStatement(Sql);
 
			//         pstmt.setInt(1,new Integer(summaryData.get("ag1")));
			//         pstmt.setInt(2,new Integer(summaryData.get("sl1")));
 
			pstmt.setString(1, (String) summaryData.get("ag1"));
			pstmt.setString(2, (String) summaryData.get("sl1"));
			pstmt.setString(3, (String) summaryData.get("datetime"));
			pstmt.setString(4, (String) summaryData.get("t1"));
			pstmt.setString(5, (String) summaryData.get("ag1_inst"));
			pstmt.setString(6, (String) summaryData.get("p1"));
			pstmt.setString(7, (String) summaryData.get("d_ms"));
			pstmt.setString(8, (String) summaryData.get("d_u_m"));
			pstmt.setString(9, (String) summaryData.get("con_e"));
			pstmt.execute();
 
			pstmt.close();
			conn.close();
			conn = null;
 
			//System.out.println( "theconnection is closed "+conn );
		} catch (Exception sq) {
			sq.getMessage();
		}
 
	}
 
}

Open in new window

0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 800 total points
ID: 24413136
I will let CEHJ help you from here, but here is a sample tnsnames.ora just in case you don't have one setup. At least verify Oracle connectivity outside JDBC for sanity check. Since you already have Oracle client on the machine, it is quick to test tnsping and sqlplus


# Replace CAT with your database instance name
# Replace the ip address with your server's ip address
# Save to {ORACLE_HOME}/network/admin/tnsnames.ora
# Then verify with:  tnsping CAT
# And:  sqlplus scott/tiger@CAT            <-- change scott/tiger to a valid user/pass
CAT =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = CAT)
    )
  )

Open in new window

0
 
LVL 10

Author Comment

by:aman0711
ID: 24413170
hi mrjoltcola,
   
                I did sqlplus scott/tiger@CAT    on my database (changed the parameters :-) lol) and it came as connected
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24413186
What happens when you try to issue the same INSERT statement as thru JDBC?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 600 total points
ID: 24413187
Check the connectivity per mrjoltcola's instructions. You shouldn't have persistence code mixed in with your core entity classes anyway
0
 
LVL 10

Author Comment

by:aman0711
ID: 24413195
Connectivity is perfect :(
   I can do everything, but dont know why this code is giving the error :(
0
 
LVL 48

Assisted Solution

by:schwertner
schwertner earned 400 total points
ID: 24413283
this is connection error.
I couldn't find where you prepare the connection string, but supply
a working example.
Try to use simple code,

***********************************************************
* Reading from scot/tiger table
**********************************************************
 
import java.sql.*;
 
import oracle.jdbc.pool.OracleDataSource;
 
class first {
public static void main (String args []) throws SQLException {
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//oralin3:1521/phr7b");
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp ORDER BY ename");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
 
 
===============================================================
Invoking PL/SQL stored procedure from a Java class
using JDBC thin driver
 
Works fine on Jdeveloper
===============================================================
 
 
Store this Oracle PL/SQL procedure under scott/tiger account.
It has 2 IN parameters and 2 OUT parameters.
 
 
CREATE OR REPLACE PROCEDURE fitnes_selector
       (p_p1 IN INTEGER,
        p_p2 IN VARCHAR2,
        p_p3 OUT INTEGER,
        p_p4 OUT VARCHAR2)
IS
BEGIN
   p_p3 := p_p1 + 10;
   p_p4 := p_p2 || '   '  || 'ADDITIONAL STRING';
END;
/
 
 
This java class will invoke the procedure above using
Oracle JDBC thin driver.
 
 
import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;
 
class StProcExample {
     public static void main(String[] args)
     throws SQLException {
     int ret_code;
     try {
          System.out.println("Begin of the play  ");
          // Create DataSource and connect to the local database
          OracleDataSource ods = new OracleDataSource();
          ods.setURL("jdbc:oracle:thin:@//oralin3:1521/phr7b");
          ods.setUser("scott");
          ods.setPassword("tiger");
          Connection conn = ods.getConnection();
 
          // Invoke stored procedure
            int  p1 = 10;
            String p2;
            p2 = "Fitness";
            int  p3;
            String p4;
            CallableStatement pstmt = conn.prepareCall("{call fitnes_selector(?,?,?,?)}");
            pstmt.setInt(1, p1);
            pstmt.setString(2, p2);
            pstmt.registerOutParameter(3, Types.INTEGER);
            pstmt.registerOutParameter(4, Types.VARCHAR);
            System.out.println("Midlle of the play  ");
            pstmt.executeUpdate();
 
            int o_empno = pstmt.getInt(3);
            String o_ename = pstmt.getString(4);
 
           System.out.print("The returned values are "
                             +o_empno +" "+ o_ename);
           pstmt.close();
           conn.close();
        } 
    catch  (SQLException e) 
            { ret_code = e.getErrorCode();
              System.out.println(ret_code + "  " + e.getMessage()); 
            }
                      }
     }

Open in new window

0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 800 total points
ID: 24413324
Which version of the odjbc jar are you using? Check that it is at least up to date with the Oracle client you installed.

Check your Oracle alert log for any odd messages.

Turn on JDBC tracing (I forget the exact steps, its usually as simple as setting a flag to true, perhaps CEHJ can help there).
0
 
LVL 10

Author Comment

by:aman0711
ID: 24413391
Hmmm... ok Seniors.
Will try that as well. I put the latest ojdbc14.jar now :-(
0
 
LVL 92

Assisted Solution

by:objects
objects earned 200 total points
ID: 24438234
check your classpath for any conflicting jars.

also do you have any working code that accesses that oracle db? If so, check the driver and connection settings used there to see whats being used.

0
 

Expert Comment

by:brk3483
ID: 24730452
Hi,

I have encounter the same problem with a standalone application.
This error was raising sporadicly after varing time the applicaion was runing.
I also searched the web and found nothing helpful so i will post my conclusions here, maybe it will help someone.

The error: java.sql.SQLException: Io exception: Got minus one from a read call. was a result of a DB error, i guess you get that error when the DB is up but the driver failed to obtain a connection.

In my case it was due to a failure in creating a new process.
Alert log error: Process m000 died, see its trace file
trace log: Process m000 is dead (pid=3697, state=3):Unable to schedule a MMON slave at: Auto Flush Main 1  Attempt to create slave process failed.  Can happen for several reasons:    - No process state objects    - Reached OS set limits    - A shutdown was going on
if your code is correct and you just need more connections you can increase the number of processes (in the DB/OS) or set a limit to the connection pool.

in my case what caused the processes creation failure is that i had an increasing number of open connections.

the OJDBC classes uses an implicit connection pool. when i used my own connection pool mechanism each time i asked my connection pool for a connection the OJDBC classes created a new connection pool.
When i closed the connection handle the connection stayed open under the implicit connection pool.

if it will help someone i can post my working code with the OJDBC connection pool.

plus here is a link to the Oracle OJDB drivers download center, please note that there are many versions of the OJDBC14.jar and you need to use the one applicable to the version of the oracle DB you are using.
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
 
0
 

Expert Comment

by:ModernMatt
ID: 25856033
Code Replaced by member request

ModernMatt
EE Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question