Link to home
Start Free TrialLog in
Avatar of aman0711
aman0711

asked on

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

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you post your code, together with the exact stack trace?
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.
Avatar of aman0711
aman0711

ASKER

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

SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
>>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?
Yes Charles, I have inserted data in the past, but this is the first time I saw this message,
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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi mrjoltcola,
   
                I did sqlplus scott/tiger@CAT    on my database (changed the parameters :-) lol) and it came as connected
What happens when you try to issue the same INSERT statement as thru JDBC?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Connectivity is perfect :(
   I can do everything, but dont know why this code is giving the error :(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmmm... ok Seniors.
Will try that as well. I put the latest ojdbc14.jar now :-(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
 
Code Replaced by member request

ModernMatt
EE Moderator