June 16, 2014

java.lang.ArrayIndexOutOfBoundsException while executing batch Statements in Java

I have created a PreparedStatement to execute a batch of insert statements. But while executing,  the below exception occurred.


java.lang.ArrayIndexOutOfBoundsException: 22 at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:207) at oracle.jdbc.driver.T4C8Oall.readRXD(T4C8Oall.java:745) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:371) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:205) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:548) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217) at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1115) at oracle.jdbc.driver.OraclePreparedStatement.executeForRowsWithTimeout(OraclePreparedStatement.java:13106) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:13246) at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:248) at XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 



Solution:

After googling, I realized that the PreparedStatement is not accepting more than 6 parameters. Below is the statement I have used.
PreparedStatement stmtQuestions = conDB.prepareStatement("INSERT INTO "+Properties.DB_TABLE +" values(?,?,?,?,?,?,?)");
         
I changed the statement to below which avoid the above exception and program was executed successfully.
Statement stmtQuestions=conDB.createStatement();
String query="INSERT INTO "+Properties.DB_TABLE +" values('"+id+"',"+sid+","+qid+",'"+sqText+"','"+sqSText+"','"+qType+"','"+qoType+"')";
stmtQuestions.addBatch(query);

May 14, 2014

Using excel file as DB and read data from Java

We can use an excel file as a data base. Using java we can create connection to excel file and execute sql query as we do with database. Use the below code to use excel file as a DB and read data from it using java.

String stExcelFile=”c:\\temp\\test.xls”;
String stSheetName=”Sheet1”;
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conExcel =
            DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" +
                                        stExcelFile +
                                        ";DriverID=22;READONLY=false");
        Statement stmtExcel = conExcel.createStatement();
        ResultSet rsExcel =stmtExcel.executeQuery("Select * from [" + stSheetName + "$]");
while (rsExcel.next()) {
System.out.println(“id: ”+rsExcel.getString(“id”)));
System.out.println(“name: ”+rsExcel.getString(“name”)));
}
rsExcel.close();
stmtExcel.close();
conExcel.close();

April 24, 2014

oracle.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/Connection1DS

Issue: 

<LifecycleImpl> <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase RENDER_RESPONSE 6
oracle.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/Connection1DS
                at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1476)
                at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:332)
                at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
                at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:592)
                at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:422)
                at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:8995)
                at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4603)



Solution:

Check the connection in AppModule. To check,

  • Right click on AppModule
  • Select Configurations option
  • In the Names, select AppModule Local, the corresponding properties will be displayed on the right side of the window
  • Check the JDBC Name/Data source value. It should be the name which you have given to the connection created in your application. If the value is not correct, Select the property and click on Edit button to change the value