随笔-11  评论-5  文章-1  trackbacks-0
/*
 * Created on 2006-8-16
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 
*/

package  com.belstar.crocodile.input;

import  java.sql.Connection;
import  java.sql.PreparedStatement;
import  java.sql.ResultSet;
import  java.sql.SQLException;
import  java.sql.Statement;
import  java.text.DateFormat;
import  java.util.Hashtable;
import  java.util.Properties;

import  javax.jms.QueueConnection;
import  javax.jms.QueueConnectionFactory;
import  javax.naming.Context;
import  javax.naming.InitialContext;
import  javax.naming.NamingException;
import  javax.sql.DataSource;
import  javax.transaction.UserTransaction;

import  com.belstar.crocodile.scan.JobQueueVB;
import  com.belstar.crocodile.util.ConnectionLocator;
import  com.belstar.crocodile.util.JndiNames;
import  com.belstar.crocodile.util.JobState;

/**
 * 
@author  Administrator
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 
*/

public   class  Test  {
    
private  String strJNDI  =   " jdbc/Crocodile " ;

    
private   static  java.sql.Connection getConnection;
    
private  DateFormat dateFormat  =  DateFormat.getDateInstance();

    
public  Test()  {
    }


    
public  Test(String strJNDI)  {
        
this .strJNDI  =  strJNDI;
        getConnection 
=   null ;
    }

    
public   void  mm(String d)  throws  SQLException, NamingException  {

        Hashtable ht 
=   new  Hashtable();
        DataSource ds 
=   null ;
        Statement stmt 
=   null ;
        ResultSet rs 
=   null ;
        Connection myConn 
=   null ;
        UserTransaction tx 
=   null ;

        String str1 
=   " update fuck set id='222' where name='1' " ;
        String str2
= " select * from JobQueue where FileName = ' " + d + " ' and JobState= " + JobState.SAVEOK + "" ;
        
try   {
            getConnection 
=
                ConnectionLocator.getInstance().getConnection(
" jdbc/Crocodile " );
            Properties p 
=   new  Properties();

            p.put(
                Context.INITIAL_CONTEXT_FACTORY,
                
" com.ibm.websphere.naming.WsnInitialContextFactory " );
            p.put(Context.URL_PKG_PREFIXES, 
" com.ibm.ws.naming " );
            p.put(Context.PROVIDER_URL, 
" iiop://localhost:2809/ " );
            InitialContext ctx 
=   new  InitialContext(p);
            System.out.println(JndiNames.DataSource 
+  ctx);
            tx 
=  (UserTransaction) ctx.lookup( " java:comp/UserTransaction " );
            
// 连接工厂
            System.out.println(tx);
            tx.begin();
            PreparedStatement pstmt 
=  getConnection.prepareStatement(str1);
             PreparedStatement pstmt1
= getConnection.prepareStatement(str2);
            System.out.println(str2);
            pstmt.executeUpdate(str1);
            rs 
=  pstmt1.executeQuery(str2);
            rs.next();
            
// System.out.println("22222222222222222"+rs.getString(""));
            System.out.println( " Success! " );
            tx.commit();
            
// pstmt.close();
            
// getConnection.close();
        }
  catch  (Exception E)  {
            
try   {
                tx.rollback();
            }
  catch  (Exception e)  {
            }

            System.out.println(
" 事务发生错误,事务被取消!  " );
        }


    }


}

posted on 2006-08-20 11:35 Crespo 阅读(872) 评论(0)  编辑  收藏 所属分类: Java web

只有注册用户登录后才能发表评论。


网站导航: