Adding to a Collection using JDBC

I'm trying to add to a Collection via JDBC but have had no luck with getting the ResultSet into the Collection and would be grateful for some pointers in the right direction in the while (rs.next()) block:
public void getMembers(BwGroup group) throws CalFacadeException {
     Class.forName("com.mysql.jdbc.Driver");
     String url = "jdbc:mysql://localhost/loginlist";
     Connection conn = null;
     Collection<BwPrincipal> ms = new TreeSet<BwPrincipal>();
      try {
         conn = DriverManager.getConnection(url, "user", "pword");
         PreparedStatement ps = conn.prepareStatement("SELECT * FROM list WHERE list='" + group +"'");
         ResultSet rs = ps.executeQuery();
            while (rs.next()) {
               BwPrincipal = new bp(rs.getString(1));
               ms = addAll(bp);
           group.setGroupMembers(ms);
           rs.close();
           ps.close();
           } catch (Exception e){
            e.printStackTrace();
           } finally {
         if (conn != null) {
        conn.close();
    }I'm getting errors regarding incompatible types for the BwPrincipal line and addAll being an unfound symbol (though I had thought that it was a method to add to Collections). If I try to call BwPrincipal as BwPrincipal bp = new bp(rs.getString(1)); then the addAll error disappears but the programme cannot see BwPrincipal as a class. I feel as if I'm going around in circles at the moment.

BaroqueThoughts wrote:
As you say, I'm trying to call something along the lines of
ms= rs.getString(1);but get an incompatible string back. The reading that I had done suggested addAll but I've probably misunderstood in trying to get this to work. If I try
ms.add(rs)then the compiler doesn't like the add method (add cannot be applied to java.sql.ResultSet)Well it can't. Why did you try that, though? To be honest, if you can't figure this out yet, JDBC is probably a step too far at the moment. Re-visit the basics, because you clearly don't understand them yet, and you'll struggle forever if you carry on down this path as-is

Similar Messages

  • How to call BULK COLLECT using JDBC in JSP?

    Hi
    I am using BULK COLLECT instead of CURSOR in my Stored Procedure.
    How to use these stuff in JDBC.
    If i am using CURSOR means
    cs.registerOutParameter(1,oracle.jdbc.driver.OracleTypes.CURSOR);
    is used.
    Which types i have to use?
    I am retriving morethan one record using FOR. LOOP in SP and before that
    BULK COLLECT is used in SELECT query..
    Can you give jsp code for this?
    Thanks

    you may find related sample jdbc code on otn - http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
    Best regards.

  • Inserting oracle objects / collection using JDBC

    Hi people,
    I want to insert objects with collections(nested tables) into oracle database using my java JDBC. I believe there are two ways, one using strong types and the other as weak. I am using the weak types.
    This is what I have got so far:
    create or replace type town_ty as object(
    name varchar2(20)
    create or replace type country as object (
    name varchar2(20),
    towns town_ty
    create table country_tab of country_ty;
    Can any one kindly give or show me an example how to insert data into the above table using weak typed JDBC?
    Thanks very much

    Hi
    You should find what you are looking for in the samples provided here http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html.
    HTH
    Chris

  • HELP: collection as in parameter of SP using jdbc

    Hi, everyone:
    i'm trying to pass an array of int value to a stored_procedure using jdbc, but i cannot figure out how to write the exact code.
    i always get the same exception: java.sql.SQLException: invalid name schema.
    i have searched this section and found some examle(Call a procedure/function with an array as argument i tried that example code, but it cannot work too, the same exception.
    here is my jdbc code:
    String driver = "oracle.jdbc.driver.OracleDriver";
    String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:test";
    Connection conn = null;
    Class.forName(driver);
    conn = DriverManager.getConnection(strUrl, "zzuliTV", "123456");
    CallableStatement proc = null;
    proc = conn.prepareCall("{ call TEST_TABLE_INT_PARAM(?,?) }");
    int elements[] = { 1, 2, 3, 4 };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TEST_PACKAGE.ID_TABLE", conn);
    //ARRAY aArray = new ARRAY(desc, conn, elements);
    //proc.setInt(1,-1);
    //proc.setArray(2, aArray);
    //proc.execute();
    proc.close();
    conn.close();
    pl/sql code:
    create or replace
    PACKAGE TEST_PACKAGE AS
    type ID_TABLE is table of number(10,0);
    END TEST_PACKAGE;
    in the jdbc code, the statement "ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TEST_PACKAGE.ID_TABLE", conn);" caused the exception.
    i have tried the code "ArrayDescriptor.createDescriptor("ID_TABLE", conn);" or written the pl/sql nested table globally or written an varray instead, but all failed, always the same exception.
    i use oracle 11g.
    Could anyone help me, thanks a lot.

    The error might be caused by your collection being defined inside of "TEST_PACKAGE", which I presume is a PL/SQL package.
    JDBC does not support Object nor Collection types defined inside packages.
    So, your attempt to globally define your "ID_TABLE" is the correct way to go.
    create type id_table as table of integer;
    or
    create type id_table as varray(#) of integer;
    Both are valid global definitions. I think that you said that you tried this unsuccessfully.
    You may want to try rewriting your elements declaration as follows.
    int elements\[] = new int\[]{1, 2, 3, 4};
    However, your declaration is probably fine. Another suggestion is to use CallableState.setObject() instead of setInt() and setArray().
    proc.setObject(1, new Integer(-1));
    proc.setObject(2, aArray);
    Also note that for 11g, the driver class is "oracle.jdbc.OracleDriver"
    Only other thing I can think of is to make sure the collection is defined in your schema or, if another, you have permission to it.
    That's all I can think of. Here is a link that describes using collections with JDBC. You may find it useful.
    http://st-doc.us.oracle.com/11/111/java.111/b31224/oraarr.htm#g1072333

  • How do you retrieve a Collection of objects using JDBC?

    How do you retrieve a Collection of objects using JDBC.
    MORE INFO:
    I have created a class i.e. Account class and I want to retrieve all the accounts previously created for accounts in my Mysql database..
    my method would retrieve an array of Account instances in the database i.e.
    public Vector retrieveAccounts();

    Connection con = null;
    ArrayList accounts = new ArrayList();
    try{
      con = DriverManager.getConnection(...);
      PreparedStatement ps = con.prepareStatement("select * from accounts");
      Resultset rs = ps.executeQuery();
      while (rs.next()) {
        Account account = new Account(rs.getString(1), rs.getString(2), ...);
        accounts.add(account);
      Account[] account_array = new Account[accounts.size()];
      accounts.toArray(account_array);
    catch (SQLException sqle) {
       sqle.printStackTrace();
    finally {
      if (con != null) {
        con.close();
    }should pretty much to what you want, you will obviously need to change it so that, a) the SQL query is correct and b) the Account class is correct and c) the correct values are taken from the result set to create an account.

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • After adding seperate performance collections to MAP 9.1 database, the database has become corrupted

    Hi,
    I have installed MAP 9.1(9.1.265.0) on my notebook, with Windows 7 Enterprise. The inventory of our environment was successfull and I have successfully added some performance collections to the database.
    First I ran the performance collection for one hour, then added a performance collection of one week. this was okay.
    Then I waited one week and added another collection of about five days. That collection would not stop: It was scheduled to run between 2014-07-28 12:49:31 until 2014-08-01 05:00:04. But it was still running at 2014-08-01 05:30:25. I waited for a little
    bit longer, but the collection kept on running according to the status screen.
    So I cancelled out of the collection at 2014-08-01 05:45. In the performance data it said that the colection ran from Jul 14 2014 08:04 AM until Aug 1 2014 4:57AM. So that looked okay.
    But now, when I try to Get the performance metrics data from MAP, it states that I have to do a "Refressh Assessment", because I problably have cancelled out of a collection. This "Refresh Assessment" wil run for about an hour and than
    completes with a message "Failed"
    I get these errors in the MapToolkit.log
    <2014-08-05 05:14:51.09
    AssessInventoryWorker@StoredProcAssessment,I> RunAssessment() - [Perf] [[Perf_Assessment].[ClearPerfdata]] : 125 ms
    <2014-08-05 05:14:56.13
    AssessInventoryWorker@StoredProcAssessment,I> RunAssessment() - [Perf] [[Perf_Assessment].[CreateTimeIntervals]] : 5039 ms
    <2014-08-05 05:22:47.76
    AssessInventoryWorker@StoredProcAssessment,I> RunAssessment() - [Perf] [[Perf_Assessment].[CreateMetricsPerTimeInterval]] : 471591 ms
    <2014-08-05 05:52:54.66
    AssessInventoryWorker@DataAccessCore,W> DoWorkInTransaction<T>() - Caught InvalidOperationException trying to roll back the transaction: This SqlTransaction has completed; it is no longer usable.
    <2014-08-05 05:52:54.79
    AssessInventoryWorker@DataAccessCore,W> DoWorkInTransaction<T>() - Caught a SQL transaction timeout exception. Will retry 3 more time(s). Retrying in 5000 milliseconds.
    <2014-08-05 05:53:15.86
    AssessInventoryWorker@DataAccessCore,W> OpenConnection() - Caught a SqlException trying to connect to the database.  Will retry connection 3 more time(s).  Retrying in 5000 milliseconds.
    <2014-08-05 05:53:20.99
    AssessInventoryWorker@DataAccessCore,W> OpenConnection() - Caught a SqlException trying to connect to the database.  Will retry connection 2 more time(s).  Retrying in 10000 milliseconds.
    <2014-08-05 05:53:45.00
    AssessInventoryWorker@DataAccessCore,W> OpenConnection() - Caught a SqlException trying to connect to the database.  Will retry connection 1 more time(s).  Retrying in 15000 milliseconds.
    <2014-08-05 06:24:03.69
    AssessInventoryWorker@DataAccessCore,W> DoWorkInTransaction<T>() - Caught a SQL transaction timeout exception. Will retry 2 more time(s). Retrying in 10000 milliseconds.
    <2014-08-05 06:54:13.91
    AssessInventoryWorker@DataAccessCore,W> DoWorkInTransaction<T>() - Caught a SQL transaction timeout exception. Will retry 1 more time(s). Retrying in 15000 milliseconds.
    <2014-08-05 07:24:28.99 AssessInventoryWorker@Analyzer,E> RunAssessments() - Assessment threw an exception:
    <2014-08-05 07:24:29.03
    AssessInventoryWorker@AssessInventoryWorker,I> AssessmentCompletedEventHandler: Assessment completed event.
    <2014-08-05 07:24:29.09
    AssessInventoryWorker@TaskProcessor,I> WorkerCompleted: Worker: 'AssessInventoryWorker'
    <2014-08-05 07:24:29.15 TID-16@TaskProcessor,I> Run: Completed. Status: Failed
    Is there maybe a restriction to the intervalls of adding performance collection data, or is there something else I am doing wrong?
    (I made a backup of the database after the first week of performance data, that database is still usable, so I can try to add more performance collections to that version of the database)
    I hope someone has an idea what is going on.
    Thanks!

    Time between isn't the problem. If you look in the log file, SQL is timing out. I think the problem is machine resources and time related. After the performance data collection has run for the predefined amount of time, MAP has SQL execute various assessments
    on the data to aggregate the raw data into something MAP can use. The more raw data that exists, the longer SQL will take and the more CPU and memory resources SQL will need.
    I would recommend that you have at least 4 cores or vCPU's and 6-8 GB of memory dedicated to the machine on which MAP is running. I would also follow the directions in this Wiki article to increase the timeout in MAP so that MAP will give SQL the time it
    needs to complete the job.
    http://social.technet.microsoft.com/wiki/contents/articles/10397.map-toolkit-increasing-the-sql-database-timeout-value.aspx
    Please remember to click "Mark as Answer" on the post that helps you, and to click
    "Unmark as Answer" if a marked post does not actually answer your question. Please
    VOTE as HELPFUL if the post helps you. This can be beneficial to other community members reading the thread.

  • Calling a stored procedure with VARRAY as out parameter using JDBC

    Hi,
    I want to use the data type VARRAY as an out parameter in an Oracle stored procedure. I want to call the stored procedure from
    my java program using JDBC.
    I'm using Oracle 8.1.5 for Windows NT.
    Please help me.
    Thanks
    Sumanta
    null

    Originally posted by JDBC Development Team:
    It's very similar to other datatype except that it uses OracleTypes.ARRAY typecode and the value is mapped to a oracle.sql.ARRAY instance. The code looks as follows --
    cstmt.registerOutParameter (idx, OracleTypes.ARRAY, "VARRAY_TYPE_NAME_HERE");
    cstmt.execute ();
    ARRAY array = (ARRAY) cstmt.getObject (idx);
    Thanks for your reply.
    I have to use:-
    OracleCallableStatement cs1 = (OracleCallableStatement )conn.prepareCall
    ( "{call proj_array(?)}" ) ;
    for retrieving a collection as an OUT parameter.
    This gives me the errors:-
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Blob getBlob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Array getArray(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Clob getClob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Ref getRef(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    How do I get rid of these errors?
    null

  • Invalid table name  error when updating object in collection using SQL

    Hi,
    I have pl/sql code where I am selecting a object from a collection using sql select query. I am processing this record and now I want to update the collection with the new object. ie. ensure that the object that was fetched be removed and this new one be added.
    considering my_ot is the object type and my_tt is the table type.
    DECLARE
    my_col my_tt;
    my_col1 my_tt
    my_var my_ot;
    my_var2 VARCHAR2(10);
    BEGIN
    // populating my_col1 with select query
    //populating my_col with select query
    FOR my_col1.FIRST .. my_col.LAST LOOP
    //populating my_var2
    BEGIN
    SELECT my_ot(c.field1, c.field2 ,c.field3) INTO my_var FROM TABLE(my_col) c WHERE c.field3 = my_var2
    //processing the field my_VAR
    UPDATE TABLE(my_col) c SET c.field1 = my_var.field1 , c.field2 = my_var.field2 , WHERE c.field3 = my_var.field3;
    EXCEPTION WHEN NO_DATA_FOUND
    my_col.EXTEND;
    my_col(my_col.LAST) := // new my_ot object
    END;
    END LOOP;
    Here, when compiling the update query is not being compiled. I am getting a error 'invalid table name'. Is there any way to modify an object in the collection without knowing its index?
    If not, is it possible to find the index of a object in the collection in select query?
    Thanks in advance
    Paddy

    Hi,
    Is there any way to find the index of a object in the collection? Then I will simply replace the object at that index, right!
    Thanks
    Paddy

  • Error Adding object to collection

    Hi all... I'm using Toplink + ADF Faces...
    We have the following problem: There are 2 tables involved, table A and table B
    Table B has a FK to table A, therefore a one-to-one mapping from B to A and a one to many mapping (collection) from A to B.
    What I want to do is to add an object of type B to the collection of an A object. I'm showing an input form for the constructor of type B, a submit button, and a read only table bellow to show the items of the collection. I have done this several times and worked fine, now I have NO clue why this is not working.
    What I used to do to achieve this is to call the method of the type A "addB(B)" (to add the object) and then the "Execute" operation (to refresh the table shown) of the collection in which the addB method is adding objects.
    What I get is just:
    2006-11-17 13:53:30.421 WARNING JBO-29000: Unexpected exception caught: java.lang.NullPointerException, msg=null
    2006-11-17 13:53:30.421 WARNING java.lang.NullPointerException
    and no more details.... :-S
    Does anyone know why this could be happening???
    or
    Is there some other way of adding objects to a collection using ADF and toplink?? Any suggestion is more than welcome!! I've been trying for too long to solve this... :-(
    Thanks in advance

    Here is another symptom:
    a few days ago, I developed a search page of objects of type "C". This type, has a collection of objects of type "B". This page is working fine, now... I do exactly the same steps to create a new page with the same search functionallity, and I get the same NullPointerException described above (with no extra information).
    Since the development of that working page until now, I manually added the mapping of table "A", which was not mapped by the time we developed the working search page. So I guess something is wrong with this new mapping.
    Here are the steps i did to map the new table "A" and define the relationship with table B (through a foreing key defined in DB):
    - created Java objects from tables for table "A".
    - added a FK from "B"->"A" in table "B" in the Offline Database Sources (just like the FK in the real DB)
    - added a ValueHolder attribute to class "B" (with the appropiate get and set, and initializing it in the constructor of class "B")
    - added a List attribute in class "A" of objects of type "B" (with the appropiates add, remove, get and set methods), and initializing the List as a new ArrayList in the constructor.
    - in the toplink map, mapped the new attributes:
    one-to-one for the Valueholder in class "B" (using the appropiate FK)
    one-to-many for the List attributes in class "A" (using the appropiate FK)
    - refreshed all possible datacontrol
    And thats it... am I doing something wrong or missing something??
    Is there any other way to map a new table into an existing toplink mapping? I'm using Jdev 10.1.3 Integrated workbench...
    I will really appreciate any suggestion or comment, I really have no clue why this is happening.... Thanks in advance

  • NCHAR issue with oracle database using JDBC adapter

    Hi,
    We have a requirement to develop an XI interface from FTP server(File adapter) to oracle database using JDBC adapter. In the oracle database table few fields are of type NCHAR/NVARCHAR. when we try to insert the character(A,B,c..) values into oracle table fields of type NCHAR/NVARCHAR, we are getting the following error message in the JDBC adapter audit log. IF we pass the numeric value to the same field, then we are able to insert the records successfully.
    Unable to execute statement for table or stored procedure. 'IPCSDD_DOWNLOAD_PROCESS' (Structure 'StatementName1') due to java.sql.SQLException: ORA-00904: "P": invalid identifier
    2010-10-19 22:29:59 Error JDBC message processing failed; reason Error processing request in sax parser: Error when executing statement for table/stored proc. 'IPCSDD_DOWNLOAD_PROCESS' (structure 'StatementName1'): java.sql.SQLException: ORA-00904: "P": invalid identifier
    2010-10-19 22:29:59 Error MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'IPCSDD_DOWNLOAD_PROCESS' (structure 'StatementName1'): java.sql.SQLException: ORA-00904: "P": invalid identifier
    Please find the system information below.
    Oracle version- 10.2.4
    XI version - 3.0/ service pack 19
    JDBC driver- oracle.jdbc.driver.OracleDriver
    Please suggest.
    Thanks,
    Venkata
    Edited by: Venkata Narayana  Eepuri on Oct 21, 2010 12:10 AM

    Dear Venkata Narayana,
    Concerning the error, kindly go through the following note :
    731 - Collective note: ORA-00904
    follow the recommendations mentioned in that and please check if that helps.
    Best Regards
    Nishwanth

  • Urg:Executing SQL From Java App using Jdbc Driver

    Hi
    I am using JDBC Driver version 9.0.1.1.0.
    I am running this in Thin Client Mode
    My Code Snippet Looks Like This:=
    ==========================================================
    String url = "jdbc:oracle:thin:@localhost:1521:VpDb";
    String userName = "scott";
    String password = "tiger";
    Connection conn = null ;
    Statement st = null ;
    ResultSet rs = null ;
    String categoryCode="ABC";
    try
    conn = DriverManager.getConnection (url, userName, password);
    st = conn.createStatement ();
    String sqlStatement = "Select Count(*) From News Where CategoryCode=" +"\'" + categoryCode + "\'" + ";";
    System.out.println(sqlStatement);
    rs = st.executeQuery ( sqlStatement );
    if( rs.next() )
    System.out.println("Headline Exists");
    else
    System.out.println("No Headline Exists");
    catch (SQLException e )
    System.out.println();
    System.out.println (" SQL ERROR IN IS_NEWS_EMPTY: " + e) ;
    =========================================================
    I have added the classes12.zip and nls_charset12.zip in the classpath.
    Now when i run this it gives me an error saying the following error message:-
    SQL ERROR IN IS_NEWS_EMPTY: java.sql.SQLException: ORA-00911: invalid character
    Can anyone help me with this as to whats going wrong because the exact equivalent of my sqlStamenet runs on SQL command line but not from java code.Why??
    Any Help appreciated
    Thanks
    Mum

    I think it is complaining about the ";" that you add at the end of your string. You don't need to add that to the query.

  • Error while connecting to Oracle db using jdbc

    When I try to execute a java class which has to access data in
    the Oracle db using Jdbc connection, get an error --
    Appln- pathname/filename is attempting to call the OCI function
    (opinit) this function does not exist in ORA72.DLL.
    Exit this appln ? Yes or No
    Both oracle db & java are on the same PC.Would like to know what
    can be done to rectify this.
    Thanks.
    null

    The OCI driver 7.3 requires the 7.3 OCI to be installed (this is
    part of the client required support files or RSF). The particular
    call in question wasn't added to the OCI untill 7.3 so it
    wouldn't exist in the 7.2 OCI library.
    null

  • Using JDBC thin drivers against 9.2 DB ?

    Is anyone doing this? How? Which JDK? Which drivers?
    I would really like to uses JDBC 2.0 (classes12.zip) - but this hangs on the very first getConnect() or Driver.connect()
    Mike

    Thanks for the response.
    I understand what you are saying...
    that readers don't block writers in Oracle (the same is true in SQL Server 2000).
    However, I don't see how my test case is working correctly with Oracle (the exact same code acting as I'm thinking it should with SQL Server, but I still think it is acting incorrectly with Oracle).
    I have transaction A do this:
    update <table> set <column2>=<value> where <column1>='1'
    then I use Thread.sleep() to make that program hang around for a few minutes.
    Meanwhile I sneak off and start another program which begins transaction B. I have transaction B do this:
    select * from <table> where <column1>='1'
    and the read works immediately (no blocking... just as you have said) however, transaction A is still sleeping, it has not called commit() or rollback() yet.
    So what if transaction A were to call rollback(), the value read by transaction B would be incorrect wouldn't it ?
    Both A and B use setAutoCommit(false) to start their transactions, and then call setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED).
    Isn't that supposed to guarantee that a reader can only read what is committed ?
    And if a row is in "flux"... in the process of having one or more values changed, then the database cannot say what the value will be ?
    I can almost see what you are saying.
    In letting the reader have what it wants without making it wait, I suppose it could be said that Oracle is holding true to the "only let committed data be read"
    So if that's it, then what if I want the blocking ?
    I want an entire row to be locked until whoever it in the middle of updating, adding, or removing it has finished.
    Do you know if that can be done with Oracle ? And how ?
    Thanks again for helping me.

  • How do u automatically generate a primary key using JDBC?

    ok, basically i'm given a simple schema
    with 5 fields, one of these are made as a constraint made for primary keys.
    I am programming under Oracle, using JDBC, and everytime i insert a new record into the table using an INSERT statement it says it cant make the id null, well yeah, then how exactly do i make it generate a new ID?
    Thanks guys.

    In the table schema, the cid field is a INTEGER
    type.
    Ok i must of accidentally typed an extra digit, it's
    working now hmmm but i'm starting from this digit now
    : 1000000016
    If i go more higher and it truncates again, is there
    anyway to fix that?No. You can however write your code to verify it.
    Noting of course that the problem will next occur after 1 billion records have been added. So I would question at what rate you think that that table is going to grow.
    Of course you could create your own id but that would require modifying the table.

Maybe you are looking for