• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6813
  • Last Modified:

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?
0
aman0711
Asked:
aman0711
  • 7
  • 5
  • 5
  • +4
8 Solutions
 
CEHJCommented:
Can you post your code, together with the exact stack trace?
0
 
mrjoltcolaCommented:
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
 
aman0711Author Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
CEHJCommented:
Make sure you're using the latest greatest driver
0
 
CEHJCommented:
btw is that the first time in the app that you attempt to do a read? Have you read successfully earlier?
0
 
mrjoltcolaCommented:
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
 
aman0711Author Commented:
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
 
CEHJCommented:
>>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
 
aman0711Author Commented:
Yes Charles, I have inserted data in the past, but this is the first time I saw this message,
0
 
aman0711Author Commented:
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
 
mrjoltcolaCommented:
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
 
aman0711Author Commented:
hi mrjoltcola,
   
                I did sqlplus scott/tiger@CAT    on my database (changed the parameters :-) lol) and it came as connected
0
 
mrjoltcolaCommented:
What happens when you try to issue the same INSERT statement as thru JDBC?
0
 
CEHJCommented:
Check the connectivity per mrjoltcola's instructions. You shouldn't have persistence code mixed in with your core entity classes anyway
0
 
aman0711Author Commented:
Connectivity is perfect :(
   I can do everything, but dont know why this code is giving the error :(
0
 
schwertnerCommented:
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
 
mrjoltcolaCommented:
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
 
aman0711Author Commented:
Hmmm... ok Seniors.
Will try that as well. I put the latest ojdbc14.jar now :-(
0
 
objectsCommented:
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
 
brk3483Commented:
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
 
ModernMattCommented:
Code Replaced by member request

ModernMatt
EE Moderator
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 7
  • 5
  • 5
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now