Home » Developer & Programmer » JDeveloper, Java & XML » executeBatch flunks in Oracle 10g OCI JDBC driver
executeBatch flunks in Oracle 10g OCI JDBC driver [message #92591] Wed, 29 September 2004 05:40
Raja S
Messages: 1
Registered: September 2004
Junior Member
Hi,

I am using OCI jdbc driver for batch updates.

Following is the the code that I am using

***

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;

public class BatchUpdates
{
  public static void main(String[[]] args)
  {
    Connection          conn = null;
    Statement           stmt = null;
    PreparedStatement   pstmt = null;
    ResultSet           rset = null;
    int                 i = 0;

    try
    {
      String url = "jdbc:oracle:oci:@kctutf8";
      try {
        String url1 = System.getProperty("JDBC_URL");
        if (url1 != null)
          url = url1;
      } catch (Exception e) {
      }

      OracleDataSource ods = new OracleDataSource();
      ods.setUser("kctuser");
      ods.setPassword("kana");
      ods.setURL(url);

      conn = ods.getConnection ();

      stmt = conn.createStatement();
      try { stmt.execute(
            "create table mytest_table (col1 number, col2 varchar2(20))");
      } catch (Exception e1) {}

      pstmt = conn.prepareStatement("insert into mytest_table values (?, ?)");

        pstmt.setInt(1, 1);
        pstmt.setString(2, "row 1");
        pstmt.addBatch();
        pstmt.setInt(1, 2);
        pstmt.setString(2, "row 2");
        pstmt.addBatch();
        pstmt.setInt(1, 3);
        pstmt.setString(2, "row 3");
        pstmt.addBatch();
        pstmt.setInt(1, 4);
        pstmt.setString(2, "row 4");
        pstmt.addBatch();
        pstmt.setInt(1, 5);
        pstmt.setString(2, "row 5");
        pstmt.addBatch();
      pstmt.executeBatch();
      rset = stmt.executeQuery("select * from mytest_table");
      while (rset.next())
      {
        System.out.println(rset.getInt(1) + ", " + rset.getString(2));
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    finally
    {
      if (stmt != null)
      {
 try { stmt.execute("drop table mytest_table"); } catch (Exception e) {}
        try { stmt.close(); } catch (Exception e) {}
      }
      if (pstmt != null)
      {
        try { pstmt.close(); } catch (Exception e) {}
      }
      if (conn != null)
      {
        try { conn.close(); } catch (Exception e) {}
      }
    }
  }
}

****

When I run this class I get the following output

1, row 1
2, row 3
3, row 5
4, null
5, 

But It should have been

1, row 1
2, row 2
3, row 3
4, row 4
5, row 5

 

The same class runs fine if I use Thin driver.

Can anyone please help me solve this issue.

 Note: This happens only if case we use setString with Varchar2 in the DB. This works fine if I have two number columns

Thanks,

Raja.S
Previous Topic: Help on OAS-XML
Next Topic: business components data form wizard
Goto Forum:
  


Current Time: Fri Apr 19 02:03:38 CDT 2024