Jdbc transaction

Hi! Sorry for my English.
Can you help me with database transaction in Java.
I have a mysql db and i create a java class that need to work with transaction.
I tried with
Connection connection= new Connessione().connect();
connection.setAutoCommit(false);
Statement db = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
db.execute("update test _table set test=2");
My problem is that if i run this application without execute the commit
when i try to update the table test_table i can't because it is in lock.
Then i have an other application in cuncurrency, this can't work until the first doesn't commit.
CAN you help me with an example?
THANKS;

I don't understand;
For example client1 start a transaction , do an update and wait that user
press a button to commit;
if in the meantime client2 start its transaction, do an insert and commit i don't like that client2 suspend until user1 press a button;
in other words i need transaction for have atomic operation and rolled back if an error occur.

Similar Messages

  • UserTransaction or JDBC transaction

    Hi,
    please give suggestions...
    We are using a application server with connection pooling
    jsp and servlets are used in project
    for transactions Is userTransaction is better or JDBC transaction is better
    userTransaction may be implemented like this
    try
    getUserTransaction
    transaction.begin
    execute queries
    transaction.commit
    catch()
    transaction.setRollbackOnly
    JDBC Transaction may be implemented like this
    connection.autoCommit=false
    try
    execute queries
    connection.commit
    catch()
    connection.rollback
    which is better for scalability and performance when we have to use transactins
    in jsp/servlets
    regards

    Hi,
    You are talking about using programmatic transactions in J2EE applications.
    When developing J2EE applications, you are recommended to use the transaction mechanism provided by the application servers.
    Sometimes, JDBC transaction can undertake the whole task. However, using JTA (Java Transaction APIs) is the better choice.
    Especially when you are going to develop a lot of components (JavaBeans/ EJBs).
    Imangine if a transaction is to be finished after the coroperation of serveral objects(JavaBean/ EJB instances).
    How can you control the begining and the ending of the transaction by puting codes in these programs?
    But it is very easy to input JTA codes (just like userTransaction etc.) to implement it.
    Therefore, to use JTA is more convinient.
    Additionally, J2EE specifications recommend to use declarative transactions in EJBs. Thus transaction management could be more flexible.
    Good luck.
    Gary Wang
    Developer Technical Support
    Sun Microsystems
    http://www.sun.com/developers/support/

  • Setting JDBC Transaction Isolation

    https://community.jboss.org/wiki/ConfigDataSources
    As explained in the above URL, with JBoss, you can set the JDBC transaction isolation level in the xml file that contains the JDBC connection information.
    I've been doing some googling, but I'm not clear on how this can be done with WebLogic. Is there some kind of external file where you can set the JDBC transaction isolation level as with JBoss, or is this some kind of change that can only be made in the application code or in some file contained within the application archive file (ear, war, etc.)?

    You can set the isolation in the deployment override weblogic-ejb-jar.xml
    - http://docs.oracle.com/cd/E21764_01/web.1111/e13719/ejb_jar_ref.htm#i1116237
    - http://docs.oracle.com/cd/E21764_01/web.1111/e13719/ejb_jar_ref.htm#i1219612

  • A jdbc transaction error occur

    Hi Everybody
    A jdbc transaction error occur when I deploy the application on the server .
    Below is the stack trace
    #SAP J2EE Engine JTA Transaction : [03bfffffffd3a000ffffffc0]####Application [13]##0#0#Error#1#/System/Audit#Java###Exception #1#com.sap.engine.services.dbpool.exceptions.BaseSQLException: Cannot commit transaction from this connection of "YTSQLS2K" DataSource. This resource participates in a local or distributed transaction.
    #SAP J2EE Engine JTA Transaction : [03bfffffffd3a000ffffffc0]####Application [13]##0#0#Error#1#/System/Audit#Java###Exception #1#com.sap.engine.services.dbpool.exceptions.BaseSQLException: Cannot initiate transaction from a connection of "YTSQLS2K" DataSource. Local or distributed transaction has already started.
    #SAP J2EE Engine JTA Transaction : [03bfffffffd3a000ffffffc0]####Application [13]##0#0#Error#1#/System/Audit#Java###Exception #1#com.sap.engine.services.dbpool.exceptions.BaseSQLException: Cannot commit transaction from this connection of "YTSQLS2K" DataSource. This resource participates in a local or distributed transaction.
    Any idea about it
    I use the jdbc version in datasource <jdbc-1.x>
    is there a need to replace it with <jdbc-2.0>
    Thank You
    Syed Saifuddin

    Hibernate allows you to choose transaction manager. As Nikolay pointed out, in a JEE envirnment it's prefferable to use JTA transactions. All you need to do is to configure hibernate to use a JTA transaction manager. It is all written in the Hibernate documentations. See
    http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-j2ee
    and
    http://www.hibernate.org/42.html#A5 .
    The relevant properties that need to be set in the configuration are:
    hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
    and
    hibernate.transaction.manager_lookup_class=<Class that knows how to lookup>
    You need to implement a class that knows how to lookup user transaction in SAP J2EE Egnine.
    The class must extend org.hibernate.transaction.JNDITransactionManagerLookup and only override its abstract method getName (simply returning the lookup string). Then provide the fully qualified name as value of the property and make sure that Hibernate can load the class.
    That should work.
    HTH
    -Georgi
    Message was edited by:
            Georgi Pavlov

  • JDBC transactions in EJB 3.0

    We have an EJB 3.0 method that call some jdbc DAO methods. This DAO methods called from controller (servlet) works fine, but when called from EJB method raise the following exception:
    "java.sql.SQLException: Cannot call Connection.commit in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed."
    I think it is a JTA related error. I don't want to use JTA because I can't modify DAO (its a third party library).
    I've tried annotation @TransactionAttribute(value=SUPPORTS) in the EJB method without success.
    There is anyway to say EJB 3.0 not use JTA?
    Thank's

    Frank, yes, I can modify if it is necessary the datasource but, how can I say in the xxxx-jdbc.xml not to use JTA transactions when this data source is called inside a ejb 3.0 method?
    I'm using Jdev11g and the integrated Web Logic Server.
    Thank's

  • JDBC  Transaction is no longer active - status: 'Marked rollback'

    I'm getting the folowing issue, we are not seeing this issue if we recycle the WLS
    Using WLS V10.3.3
    Can any one suggest on this issue, how to reslove this
    85417.772: [Full GC [PSYoungGen: 117504K->0K(234880K)] [PSOldGen: 662564K->665699K(700416K)] 780068K->665699K(935296K) [PSPermGen: 133284K->132438K(225280K)], 30.2876423 secs] [Times: user=31.23 sys=0.68, real=30.32 secs]
    java.sql.SQLException: The transaction is no longer active - status: 'Marked rollback. [Reason=weblogic.transaction.internal.TimedOutException: Transaction timed out after 39 seconds
    BEA1-600C65F8B23E363DFDF0]'. No further JDBC access is allowed within this transaction.
    at weblogic.jdbc.wrapper.JTSConnection.checkIfRolledBack(JTSConnection.java:193)
    at weblogic.jdbc.wrapper.JTSConnection.checkConnection(JTSConnection.java:209)
    at weblogic.jdbc.wrapper.ResultSet.preInvocationHandler(ResultSet.java:99)
    at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
    at com.vzw.pos.cmw.ejb.service.UserProfileService.getNewUserId(Unknown Source)
    at com.vzw.pos.cmw.ejb.utils.CMWEjbUtil.createUserProfileVO(Unknown Source)
    at com.vzw.pos.cmw.ejb.utils.CMWEjbUtil.createRosterVO(Unknown Source)
    at com.vzw.pos.cmw.ejb.service.AdministrationBean.getRostersByUserId(Unknown Source)
    at com.vzw.pos.cmw.ejb.service.Administration_ujnwz8_ELOImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:39)
    at com.vzw.pos.cmw.ejb.service.Administration_ujnwz8_ELOImpl.getRostersByUserId(Unknown Source)
    at com.vzw.pos.cmw.action.CMWTopFrameAction.setUserRoleInSession(Unknown Source)
    at com.vzw.pos.cmw.action.CMWTopFrameAction.changeLocation(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor190.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.vzw.pos.cmw.filters.CMWFilter.doFilter(Unknown Source)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3710)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3676)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2272)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2178)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
    <Aug 23, 2013 10:41:53 AM EDT> <Warning> <Socket> <BEA-000450> <Socket 298 internal data record unavailable (probable closure due idle timeout), event received -32>
    <Aug 23, 2013 10:41:53 AM EDT> <Warning> <Socket> <BEA-000450> <Socket 286 internal data record unavailable (probable closure due idle timeout), event received -32>
    <Aug 23, 2013 10:41:56 AM EDT> <Warning> <Socket> <BEA-000450> <Socket 299 internal data record unavailable (probable closure due idle timeout), event received -32>
    <Aug 23, 2013 10:42:51 AM EDT> <Warning> <Socket> <BEA-000450> <Socket 286 internal data record unavailable (probable closure due idle timeout), event received -32>

    Here is DS configuration
    Initial Capacity:                  75
    Maximum Capacity:                  75
    Capacity Increment:                    1
    Seconds to trust an idle pool connection:     10
    Shrink Frequency:                    900
    Enable Connection Leak Profiling:          False
    Enable Connection Profiling:               False
    Test Frequency:                         120 seconds
    Test Connections on Reserve:               True
    Connection Reserve Timeout:               10 seconds
    Connection Creation Retry Frequency:         1
    Inactive Connection Timeout:               60 second
    Maximum Waiting for Connection:               2147483647
    Statment Cache Type:     LRU
    Statment Cache Size:     10
    Connection Creation Relay Frequency:      1
    Remove Infected Connections Enabled:      True
    Wrap Data types:     True
    Ignore In-use connections:     True

  • Grouping JMS & JDBC transaction with JTA outside of an app server

    hi,
    Can anyone help me or direct me to some code/configuration that shows how to combine JDBC + JMS into one distributed transaction outside of an app server.
    thanks in advance
    michael

    Hi,
              Well, transaction guru's please correct what I say here, but from what I
              understand of your problem here goes:
              If you begin a user transaction your are going to be starting a distributed
              transaction. That's the point of doing it, and hence that's why you have an
              XA. You have more than once resource participating in a transaction, and
              that is what UserTransaction was created for. You can't do it with a local
              transaction, which is for one resource only. I hope that answers "why
              would I need a XA". Even if both resources are hosted by WebLogic, you have
              explicitly asked for a UserTransaction...WL will optimize it if both are on
              same server, but still.. In addition, if you have a true XA data source and
              connection pool, then I would imagine that WL would list the transaction
              system of the DB too....whcih won't be local.
              As for your other problem, it seems to me that you have a connection pool of
              connections that are not XA-aware. If you set the attribute in the
              datasource and enable emulation, then the datasource becomes XA aware, but
              only sort of. WL handles the XA behaviour of that resource, but with
              limitations (you can't have more than one resource with XA emulation in the
              same Tx). If you are using a connection factory with a different store that
              uses XA-emulation, as well as straight JDBC from yet another pool using XA
              emulation, then you will also get problems. Best is to use a real driver
              that supports XA.
              Regards,
              Jon
              

  • Basic JDBC transactional question

    Hello all,
    I have (what I believe) is a basic transactional JDBC question.
    Here's what I want to do:
    begin transaction
    select a row from a table where (some condition).
    that row may or may not exist.
    if the row exists: update the row
    else if the row does not exist, insert a new row
    end transaction
    I want this entire thing to be atomic .. I don't want the select to complete, then have something else come in there before the update/insert takes place.
    I'm using MySQL .. I seem to remember hearing about some proprietary MySQL command which would do a SELECT + UPDATE atomically .. which would be fine, but I can't find it.
    Wrapping this with a row-level lock would be fine too .. I'm just not sure how to do that in JDBC.
    Thanks!
    -d

    By thte way, and not that it helps the orignal poster, who's using MySQL, but Oracle has a proprietary MERGE statement that does "insert or update" in one go. For example:
    MERGE INTO bonuses D
       USING (SELECT employee_id, salary, department_id FROM employees
       WHERE department_id = 80) S
       ON (D.employee_id = S.employee_id)
       WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
         DELETE WHERE (S.salary > 8000)
       WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
         VALUES (S.employee_id, S.salary*0.1)
         WHERE (S.salary <= 8000);

  • JDBInsight 2.0 Released - True JDBC Transaction Analysis !!!

    Check out the new product release and revised documentation at:
    http://www.jinspired.com/products/jdbinsight/downloads/index.html
    PRESS RELEASE
    =============
    DUBLIN, IRELAND - 29th October, 2003 - JInspired (www.jinspired.com), a leader
    in J2EE(tm) transaction analysis, today announced JDBInsight 2.0, the next generation
    of J2EE performance management products from JInspired.
    JDBInsight is the first product to effectively integrate Java profiling information
    with JDBC/SQL transaction analysis. Version 2.0 has numerous features derived
    from its support of the Java VM Profiling Interface(JVMPI) such as Java call stack
    analysis, cpu, blocking and waiting measurements at the transaction path level.
    Clock measurements are adjusted for blocking, waiting and gc pauses. New features
    in this release
    - New console user interface: Many new informative visualizations of J2EE transactions
    and performance execution profiles have been added. Including call stack graphs,
    entry point tree maps, sequence diagrams, call stack and transaction transcripts.
    Additional views included allow for navigation of the performance profile via
    database table or column, Java package, class, or method, technology classification,
    SQL tokens, or transaction entry points.
    - Java call stack classification engine: Developers, testers, database and J2EE
    server administrators can now better understand the interaction of various Java
    enterprise technologies with corporate databases. Classifications are available
    for Java enterprise technologies such as EJB, Hibernate, JDO, JMS, JSP, Servlets,
    JTS, JDBC, and Struts.
    - Terminal services: The terminal services add-on provides a quick and easy way
    to communicate with multiple servers without having to use a graphical user interface.
    This facilitates the streamlined connection, activation and deactivation of profiles
    on local or remote servers with the ability to control multiple servers from a
    single terminal. The terminal environment provides a powerful environment to create
    and schedule snapshot information, in order to monitor servers at regular intervals,
    with the ability to store and retrieve snapshots from any mounted drive, as well
    as providing a rich set of commands, that can be executed from saved scripts,
    to assist in analysis of this highly detailed profile data.
    - Transaction demarcations: JDBInsight 2.0 is the first performance management
    product to have the ability to detect and present resource transaction demarcations
    - allowing visual sub-transaction identification.
    - Resource Management: JDBInsight keeps counters representing objects states for
    each JDBC interception point create a resource object. When a JDBC resource changes
    state the allocation site counters are updated. This helps to pinpoint source
    code locations where resource objects are created and not closed properly or freed
    from memory. Because an interception is a combination of call stack and SQL the
    view caters for generic J2EE application frameworks which create objects based
    on application parameters and callers.
    - Xml export: Various statistical measurements can be viewed in Xml format and
    copied into applications for custom report generation.
    - Server options: Additional system properties to customize the small amount of
    overhead added during runs.
    About JDBInsight
    JDBInsight is an innovative enterprise development product, aimed at simplifying
    the performance tuning and testing of J2EE(tm) applications, which access data
    through the Java Database Connectivity (JDBC(tm)) API. JDBInsight analyses the
    access of enterprise data by J2EE(tm) client-, web-, and bean containers. The
    analysis can encompass transaction executions, from multiple J2EE(tm) containers.
    JDBInsight captures timing and execution information for enterprise data accessed
    by Servlets, JavaServer Pages, Session- and Entity Beans using JDBC(tm) or an
    Entity Bean using a container's persistence engine. JDBInsight can also profile
    non-J2EE applications that access enterprise data through the JDBC(tm) API.
    What distinguishes JDBInsight from other profiling and performance management
    tools on the market is that JDBInsight provides analysis from a sequence perspective
    instead of simply showing a call tree. Inefficiencies in J2EE applications occur
    mainly at the transaction level such as repeating the execution of a particular
    SQL locally and globally. JDBInsight facilitates the recognition of database interaction
    patterns that exhibit inefficiencies when viewed in terms of the sequential execution
    of a business and/or resource transaction.
    About JInspired
    JInspired located in Ireland, delivers JDBInsight, a comprehensive solution for
    Application Performance Tuning and Testing that focuses directly on early identification
    within the development and testing lifecycle. Jinspired offers sophisticated analytical
    tools, that capture transactional behaviour and performance timing information,
    across multiple containers in a single console, and presents this information
    intuitively to the user "Visualizing the Invisible".

    Check out the new product release and revised documentation at:
    http://www.jinspired.com/products/jdbinsight/downloads/index.html
    PRESS RELEASE
    =============
    DUBLIN, IRELAND - 29th October, 2003 - JInspired (www.jinspired.com), a leader
    in J2EE(tm) transaction analysis, today announced JDBInsight 2.0, the next generation
    of J2EE performance management products from JInspired.
    JDBInsight is the first product to effectively integrate Java profiling information
    with JDBC/SQL transaction analysis. Version 2.0 has numerous features derived
    from its support of the Java VM Profiling Interface(JVMPI) such as Java call stack
    analysis, cpu, blocking and waiting measurements at the transaction path level.
    Clock measurements are adjusted for blocking, waiting and gc pauses. New features
    in this release
    - New console user interface: Many new informative visualizations of J2EE transactions
    and performance execution profiles have been added. Including call stack graphs,
    entry point tree maps, sequence diagrams, call stack and transaction transcripts.
    Additional views included allow for navigation of the performance profile via
    database table or column, Java package, class, or method, technology classification,
    SQL tokens, or transaction entry points.
    - Java call stack classification engine: Developers, testers, database and J2EE
    server administrators can now better understand the interaction of various Java
    enterprise technologies with corporate databases. Classifications are available
    for Java enterprise technologies such as EJB, Hibernate, JDO, JMS, JSP, Servlets,
    JTS, JDBC, and Struts.
    - Terminal services: The terminal services add-on provides a quick and easy way
    to communicate with multiple servers without having to use a graphical user interface.
    This facilitates the streamlined connection, activation and deactivation of profiles
    on local or remote servers with the ability to control multiple servers from a
    single terminal. The terminal environment provides a powerful environment to create
    and schedule snapshot information, in order to monitor servers at regular intervals,
    with the ability to store and retrieve snapshots from any mounted drive, as well
    as providing a rich set of commands, that can be executed from saved scripts,
    to assist in analysis of this highly detailed profile data.
    - Transaction demarcations: JDBInsight 2.0 is the first performance management
    product to have the ability to detect and present resource transaction demarcations
    - allowing visual sub-transaction identification.
    - Resource Management: JDBInsight keeps counters representing objects states for
    each JDBC interception point create a resource object. When a JDBC resource changes
    state the allocation site counters are updated. This helps to pinpoint source
    code locations where resource objects are created and not closed properly or freed
    from memory. Because an interception is a combination of call stack and SQL the
    view caters for generic J2EE application frameworks which create objects based
    on application parameters and callers.
    - Xml export: Various statistical measurements can be viewed in Xml format and
    copied into applications for custom report generation.
    - Server options: Additional system properties to customize the small amount of
    overhead added during runs.
    About JDBInsight
    JDBInsight is an innovative enterprise development product, aimed at simplifying
    the performance tuning and testing of J2EE(tm) applications, which access data
    through the Java Database Connectivity (JDBC(tm)) API. JDBInsight analyses the
    access of enterprise data by J2EE(tm) client-, web-, and bean containers. The
    analysis can encompass transaction executions, from multiple J2EE(tm) containers.
    JDBInsight captures timing and execution information for enterprise data accessed
    by Servlets, JavaServer Pages, Session- and Entity Beans using JDBC(tm) or an
    Entity Bean using a container's persistence engine. JDBInsight can also profile
    non-J2EE applications that access enterprise data through the JDBC(tm) API.
    What distinguishes JDBInsight from other profiling and performance management
    tools on the market is that JDBInsight provides analysis from a sequence perspective
    instead of simply showing a call tree. Inefficiencies in J2EE applications occur
    mainly at the transaction level such as repeating the execution of a particular
    SQL locally and globally. JDBInsight facilitates the recognition of database interaction
    patterns that exhibit inefficiencies when viewed in terms of the sequential execution
    of a business and/or resource transaction.
    About JInspired
    JInspired located in Ireland, delivers JDBInsight, a comprehensive solution for
    Application Performance Tuning and Testing that focuses directly on early identification
    within the development and testing lifecycle. Jinspired offers sophisticated analytical
    tools, that capture transactional behaviour and performance timing information,
    across multiple containers in a single console, and presents this information
    intuitively to the user "Visualizing the Invisible".

  • JMS and JDBC Transaction

    I have recently tried using the JMS interface for AQ and I have discovered that the queue connection is a separate JDBC connection even if you create a queue connection using an OracleConnection. Is there a workaround for this? It seems a bit strange to have two connections open to the database and be forced to use an XA session in order to get the commits synchronized. Any ideas ? Below is some sample code I am using:
    queueConnection = AQjmsQueueConnectionFactory.createQueueConnection((OracleConnection)connection);
    queueConnection.start();
    QueueSession queueSession = queueConnection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
    AQjmsSession aqs = (AQjmsSession)queueSession;
    Queue queue = aqs.getQueue("TEST_SCHEMA", "TEST_QUEUE");

    Hello,
    What version are you using of the jar files? What version of the database are you using?
    From what I recall the example in <Note:301434.1> successfully reused an existing JDBC connection.
    I would be interested to see a more complete code example if this is not helpful.
    Thanks
    Peter

  • JDBC transaction isolation

    Isolation levels are:
    commited, repeatable read, uncomitted and serializable.
    As a Java programmer, where will we specify these attributes?

    kasim wrote:
    I am using just JDBC, when i program using JDBC where i need to specify these?Sorry about the previous comment. I couldn't resist.
    Anyway, see java.sql.Connection and set/get TransactionIsolation: http://java.sun.com/javase/6/docs/api/java/sql/Connection.html

  • JDBC Transaction - Exception management

    Does anybody know how to catch ALL the SQL errors that could appear in a transaction composed for instance of 10 insert ?

    List sqlExceptions = new ArrayList();
    for(int i=0; i<commands.length; i++) {
      try {
        getStatement().executeUpdate(command);
    } catch(SQLException ex) {
    sqlExceptions.add(ex);

  • JDBC, JMS and EJB transactions - possible problem?

    Hello,
              I am using Oracle 9, Weblogic 8.1 SP 4, MyEclipse and
              XDoclet.
              In my current project I have the following piece of code
              in one of my message driven beans (code cited as pseudocode
              without unnecessary details):
              * @ejb.bean name="MyMessageProcessor"
              * display-name="Display name for a MyMessageProcessor"
              * jndi-name="ejb/MyMessageProcessor"
              * description="Bean MyMessageProcessor"
              * destination-type="javax.jms.Queue"
              * transaction-type="Container"
              * acknowledge-mode="Auto-acknowledge"
              * subscription-durability="Durable"
              * generate="false"
              * @ejb.transaction type="Required"
              public class MyMessageProcessor implements MessageDrivenBean, MessageListener {
              public void onMessage(Message msg) {
                   try {
                        //obtaining connections to two different databases via JNDi
                        java.sql.Connection connOne =
                        ((DataSource)ctx.lookup("DataSourceOne")).getConnection();          
                        java.sql.Connection connTwo =
                             ((DataSource)ctx.lookup("DataSourceTwo")).getConnection();
                        // performing some UPDATEs and INSERTs on connOne and connTwo
                        // calling some other methods of this bean
                        //creating the reply JMS message and sending it to another JMS queue
                        Message msgTwo = this.createReplyMessage(msg)
                        this.queueSender.send(msgTwo);
                        //commiting everything
                        this.queueSession.commit();          
                   } catch (Exception ex) {
                   try {
                        if (this.queueSession!=null) this.queueSession.rollback();
                   } catch (JMSException JMSEx) {};     
                   this.context.setRollbackOnly();
              Some days ago (before the final remarks from my client) there used to be only one DataSource configurated on the basis of the
              connection pool with non-XA jdbc driver. Everything worked fine
              including the transactions (if anything wrong happend not only wasn't the replymessage sent, but also no changes were written
              to database and the incomming message was thrown back to the my bean's
              queue).
              When I deployed the second DataSource I was informed by an error message, that only one non-transactional resource may
              participate in a global transaction. When I changed both datasources
              to depend on underlying datasources with transatcional (XA) jdbc drivers, everything stopped working. Even if
              EJB transaction was theoretically successfully rolledbacked, the changed were written to the database
              and the JMS message wasn't resent to the JMS queue.
              So here are my questions:
                   1. How to configure connection pools to work in such situations? What JDBC drivers should I choose?
                   Are there any global server configurations, which may influence this situation?
                   2. Which jdbc drivers should I choose so that the container was able to rollback the database transactions
                   (of course, if necessary)?
                   3. Are there any JMS Queue settings, which would disable the container to send message back to the
                   queue in case of setRollbackOnly()? How should be the Queue configurated?
              As I am new to the topic and the deadline for the project seems to be too close I would be grateful
              for any help.
              This message was sent to EJB list and JDBC list.
              Sincerely yours,
              Marcin Zakidalski

    Hi,
              I found these information extremely useful and helpful.
              The seperate transaction for sending messages was, of course, unintentional. Thanks a lot.
              Anyway, I still have some problems. I have made some changes to the
              code cited in my previous mail. These changes included changing QueueSessions
              to non-transactional. I also set the "Honorate global transactions" to true.
              I am using XA JDBC driver. After setting "Enable local transactions" to false
              (I did it, because I assume that JDBC transactions should be part on the global
              EJB transaction) I got the following error:
              java.sql.SQLException: SQL operations are not allowed with no global transaction by default for XA drivers. If the XA
              driver supports performing SQL operations with no global transaction, explicitly allow it by setting
              "SupportsLocalTransaction" JDBC connection pool property to true. In this case, also remember to complete the local
              transaction before using the connection again for global transaction, else a XAER_OUTSIDE XAException may result. To
              complete a local transaction, you can either set auto commit to true or call Connection.commit() or Connection.rollback().
              I have also inspected the calls of methods of bean inside of onMessage() method just to check, whether
              the transactions are correctly initialized (using the weblogic.transaction.Transaction class).
              My questions are as follows:
              1. Any suggestions how to solve it? I have gone through the google answers on that problem and only
              thing I managed to realize that JDBC must start its own transaction. Is there any way to prohibit it
              from doing that? Can using setAutocommit(true/false) change the situation for better?
              2. How to encourage the JDBC driver to be a part of EJB transaction?
              3. As I have noticed each of ejb method has its own transactions (transactions have different
              Xid). Each method of the bean has "required" transaction attribute. Shouldn't it work in such
              way that if already started transaction exists it is used by the called method?
              4. The DataSources are obtained in my application via JNDI and in the destination environment I will have slight
              impact on the configuration of WebLogic. What is least problematic and most common WebLogic configuration which would
              enable JDBC driver to participate in the EJB transaction? Is it the WebLogic configuration problem or can it be
              solved programmically?
              Currently my module works quite fine when "enable local transactions" for DataSources is set to true, but this way
              I am loosing the ability to perform all actions in one transaction.
              Any suggestions / hints are more than welcomed. This message was posted to jdbc list and ejb list.
              Marcin

  • Distributed transactions/jdbc problem WL60

    Hi
              Our company has aworking application running on WLS5.1sp9.
              Im in the process of migrating it to WL6.0sp2.
              Our domain has 2 clusters each running 2 servers:
              1) servlet engines (handling http requests from clients, running servlets
              and jsp's)
              2) ejb containers (runnigour entities and session beans, working with Oracle
              8i database using connection pool and TxDataSource)
              The scenario:
              - a client request invokes a servlet on one of the servlet engines.
              - the servlet opens a jndi context to one of the ejb containers
              - the servlet open a transaction on a UserTransaction stub on that ejb.
              - then the servlet calls an entity bean using a home interface looked up
              using the same context.
              - the entity bean uses DataSource lookup in its own servers jndi to rerieve
              a connection.
              and then i get the following exception:
              java.sql.SQLException: No default driver for database type:
              jdbc:weblogic:jts
              at
              weblogic.jdbcbase.t3.Driver.seeIfWeNeedToInferDriverNameAndUrlFrom(Driver.ja
              va:456)
              at weblogic.jdbcbase.t3.Driver.getAllPropsFrom(Driver.java:255)
              at weblogic.jdbcbase.t3.Driver.connect(Driver.java:75)
              at weblogic.jdbcbase.jts.Driver.createRemoteConnection(Driver.java:199)
              at weblogic.jdbcbase.jts.Driver.connect(Driver.java:134)
              at
              weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java
              :44)
              at com.unisfair.util.DBHelper.getConnection(DBHelper.java:43)
              the transaction toString() gives:
              transaction=(IdHash=7541556,Name = [EJB
              UserBeanImpl.generateSessionSuffix()],Xid=2:b53da78d3c1badbb,Status=Active,n
              umRepliesOwedMe=0,numRepliesOwedOthers=1,seconds since begin=0,seconds
              left=30,activeThread=Thread[ExecuteThread: '8' for queue: 'default',5,Thread
              Group for Queue:
              'default'],ServerResourceInfo[weblogic.jdbc.jts.Connection]=(state=new,assig
              ned=none),SCInfo[ejb2]=(state=active),SCInfo[servlet2]=(state=active),SCInfo
              [ejb1]=(state=active),properties=({weblogic.transaction.name=[EJB
              UserBeanImpl.generateSessionSuffix()], weblogic.jdbc=t3://10.0.0.31:7007}))
              However the error happens on the other ejb server 10.0.0.33:7007
              It seems that the jts driver tries to get a remote connection on the server
              that coordinates the transaction but uses the deprecated t3 driver.
              I hope someone can help us since this problem is a good enough reason for us
              not moving on to WL6.0 we also looked at WL6.1 Beta and theres nothing new
              about it either.
              thanks
              Dror Last
              Senior Software Engineer
              Unisfair Inc.
              12 Yad Haruzim St. Tel Aviv 67778 Israel
              Tel: +972-3-5373738 Ext. 243
              Fax: +972-3-5373731
              GSM: +972-55-723710
              mailto:[email protected]
              http://www.unisfair.com/
              

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDBC_TX ():
    In the readme file of Oracle JDBC drivers 8.1.6.0.1 (http://technet.oracle.com/software/tech/java/sqlj_jdbc/files/Readme_01.txt)
    it mentioned that it supports "distributed transactions".
    As I understand, JDBC transaction is connection based and uses Oracle internal transaction manager. In order to do "distributed transactions", I must have at least two connections open at the same time each to its own database instance. How does the two connections coordinate the transactions? I thought in order to support "distributed transactions", one has to build a higher layer to encapsulate the two connections and therefore coordinate the distributed transactions. Any examples will be welcome.<HR></BLOCKQUOTE>
    The two branches of the transaction are coordinated using 2-phase commit.
    For samples look under
    $ORACLE_HOME/jdbc/demo/samples/oci8/jdbc20-samples/
    null

  • Need help with Kerb. jdbc from Linux to MS SQL 2008

    Hello Forum, I am getting an erro when I try to use Kerb. trusted security to connect to sql server.
    4.0 documentation reflects it's absolutely possible.
    Not only that, I have ms odbc installed on the same box and it provides Kerbers (not ntlm) connection to sql server. But java with jdbc reject doing it.
    Here is the message:
    com.microsoft.sqlserver.jdbc.SQLServerException: Integrated authentication failed. ClientConnectionId:5836ac6c-6d2e-42e4-8c6d-8b89bc0be5c9
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
            at com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:140)
            at com.microsoft.sqlserver.jdbc.KerbAuthentication.GenerateClientContext(KerbAuthentication.java:268)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2691)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
            at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
            at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
            at java.sql.DriverManager.getConnection(DriverManager.java:419)
            at java.sql.DriverManager.getConnection(DriverManager.java:367)
            at connectURL.main(connectURL.java:53)
    Caused by: javax.security.auth.login.LoginException: unable to find LoginModule class: com.sun.security.auth.module.Krb5LoginModule
            at javax.security.auth.login.LoginContext.invoke(LoginContext.java:834)
            at javax.security.auth.login.LoginContext.access$000(LoginContext.java:209)
            at javax.security.auth.login.LoginContext$4.run(LoginContext.java:709)
            at java.security.AccessController.doPrivileged(AccessController.java:327)
            at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:706)
            at javax.security.auth.login.LoginContext.login(LoginContext.java:603)
            at com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:133)
    1] Client side:
    Which OS platform are you running on? (Linux)
    Which JVM are you running on? (IBM J9 VM (build 2.6, JRE 1.6.0 Linux amd64-64
    What is the connection URL in you app? (jdbc:sqlserver://abcde24243.somebank.COM:15001;databaseName=master;integratedSecurity=true;authenticationScheme=JavaKerberos)
    If client fails to connect, what is the client error messages? (see above)
    Is the client remote or local to the SQL server machine? [Remote | Local]
    Is your client computer in the same domain as the Server computer? (Same domain | Different domains | WorkGroup)
    [2] Server side:
    What is the MS SQL version? [ SQL Sever 2008]
    Does the server start successfully? [YES ] If not what is the error messages in the SQL server ERRORLOG?
    If SQL Server is a named instance, is the SQL browser enabled? [NO]
    What is the account that the SQL Server is running under?[Domain Account]
    Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES ]
    Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[YES | NO | not applicable ]
    I currently can login from client using ms odbc sqlcmd (linux) version with trusted Kerberos connection.
    which tells me there is no problem with firewall.
    Tips:
    If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery().
    If you are using JDBC transactions, do not mix them with T-SQL transactions.
    Last but not least:
    gene

    Saeed,
    Not being versed in JAVA, I'm not sure what you're telling me. Can you tell me if this looks good? BTW, I did find out that JDBC is installed on the server as part of Coldfusion and this is what I was told:
    macromedia.jdbc.oracle.OracleDriver is 3.50
    macromedia.jdbc.db2.DB2Driver is 3.50
    macromedia.jdbc.informix.InformixDriver is 3.50
    macromedia.jdbc.sequelink.SequeLinkDriver is 5.4
    macromedia.jdbc.sqlserver.SQLServerDriver is 3.50
    macromedia.jdbc.sybase.SybaseDriver is 3.50
    Below is what I think will work, but I know it won't because of the semi colons. Can you help me fix it?
    I've the things that I think need changing are in bold.
    Thanks!
    ======
    private void dbInit()
    dbUrl = "jdbc:odbc:DRIVER={SQL Server};Database="DATADEV";Server=VS032.INTERNAL.COM:3533;", "web_user";
    try
    Class.forName("macromedia.jdbc.sqlserver.SQLServerDriver ");
    catch(Exception eDriver)
    failedDialog("Driver failed!", eDriver.getMessage());
    private void dbOpen()
    if(paramServerIP.indexOf("datadev") >= 0)
    dbPswd = "password";
    else
    dbPswd = "password";
    try
    dbCon = DriverManager.getConnection(dbUrl, paramDbUserStr,
    dbPswd);
    dbStmt = dbCon.createStatement();
    dbStmt.setEscapeProcessing(true);
    catch(Exception eDbOpen)
    failedDialog("Failed to open db connection!",
    eDbOpen.getMessage());
    private void dbClose()
    try
    dbStmt.close();
    dbCon.close();
    catch(Exception eDbClose)
    failedDialog("Failed to close db connection!",
    eDbClose.getMessage());
    }

Maybe you are looking for

  • Migrating from CR9 to CR11 Release 2 and Printronix Printer problem

    Hello, Currently we are in the midst of migrating all of our report for one of our main application from CR 9 to CR11 R2. The entire migrating, importing, as well as publishing for tall the report runs smoothly. We even can view the report once we ca

  • Shared mailbox issues

    Hi, I have a PA with access to two shared mailboxs all three outlooks are 2007, and the PA has owner permissons on both.  The PA has created "User-defined fields in Inbox" called Action and has ticked "Allow in-cell editing within Other settings.  In

  • SHOWING DYNAMIC PIE GRAPH IN HTML

    Hi, I like to generate a pie graph in HTML USING JAVA. Please tell me the way to do or any source is available to generate the pie graph. I am using Oracle8i. If anyone sends the answer it will be more helpful to me. Thanks THIRU null

  • I Need Some ripping Help

    Hello all, at this moment in time I'm in a real pridicament as I've recently started to try using the Creative Media Source Player to rip my audio CDs. Unfortunately, whenever I try to rip these CDs an error always occurs in whatever format I try to

  • Rendering - basic question

    I'm currently using Pre4 but I'm playing with the Pre9 trial (I passed on the Pre7 and Pre8 upgrades).  Anyway, why can't I get the work area to render?  I hit ENTER, the rendering progress window flashes on screen for a split second and then the cli