隨筆-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(
          " 事務發(fā)生錯誤,事務被取消!? " );
          ????????}


          ????}


          }

          posted on 2006-08-20 11:35 Crespo 閱讀(887) 評論(0)  編輯  收藏 所屬分類: Java web
          主站蜘蛛池模板: 砚山县| 响水县| 板桥市| 土默特右旗| 藁城市| 定远县| 普安县| 蒙自县| 深圳市| 腾冲县| 西华县| 灌南县| 镇巴县| 永川市| 霍邱县| 台南市| 遂平县| 饶阳县| 资兴市| 霍林郭勒市| 长葛市| 元朗区| 三门县| 涞源县| 应城市| 城口县| 高雄县| 黑河市| 宜昌市| 太康县| 蓬安县| 高州市| 湘潭县| 郧西县| 菏泽市| 山西省| 子长县| 邹平县| 平陆县| 雷山县| 新野县|