隨筆-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 閱讀(887) 評論(0)  編輯  收藏 所屬分類: Java web
          主站蜘蛛池模板: 柞水县| 禹州市| 荔波县| 汉寿县| 澳门| 姜堰市| 河北区| 淅川县| 新邵县| 古丈县| 富阳市| 基隆市| 裕民县| 平乐县| 东宁县| 额尔古纳市| 剑阁县| 蒙城县| 台东市| 虞城县| 岚皋县| 青阳县| 水富县| 忻州市| 宜春市| 敦煌市| 邢台市| 克东县| 望江县| 无棣县| 安陆市| 大关县| 九龙县| 平塘县| 伊宁县| 庆城县| 中方县| 威海市| 东台市| 齐齐哈尔市| 侯马市|