闪文书库(Www.Shanwen.Com)-欢迎广大书友光临闪文阅读
  闪文书库 > 名著小说 > IT知识库 > 未知会客室 加入书架 | 推荐本书 | 打开书架 | 章节目录 | 返回书页 | 错误/举报 | 繁體中文
第一卷 第六章

作者:未知     搜这本小说最快的更新     下载这本小说的多模式版电子书

为了方便您阅读最新章节,请记住“闪文书库”网址 www.shanwen.com,注册会员收藏您喜爱的书籍
====>>>公告:晚上6点-11点高峰期,可能出现图片打开缓慢,如果太长时间没有打开,请刷新
     第一卷第六章

    ?packagecom.mingo.sms2web.JNDICon;

    /**

    *

    Title:SMS2WEB

    *

    Description:connectanywhere

    *

    Copyright:Copyright(c)2004

    *

    Company:speedmcu

    *@authormingo

    *@version1.0

    */

    importjavax.naming.*;

    importjavax.sql.*;

    importjava.sql.*;

    importjava.io.*;

    publicclassDataConn{

    privateContextctx;

    privateDataSourceds;//数据源

    privateConnectionconn=null;//数据连接

    privateStatementstmt=null;//数据表达

    publicResultSetrst=null;//数据结果集

    publicStringsql;//sql语句

    publicDataConn(StringDataBaseName){

    init(DataBaseName);

    }

    /***********

    初始化

    ************/

    publicvoidinit(StringDataBaseName){

    try{

    ctx=newInitialContext();

    if(ctx==null)

    thrownewException("Boom-NoContext");

    ds=

    (DataSource)ctx.lookup(

    "java:comp/env/jdbc/"+DataBaseName);

    if(ds!=null){

    //System.out.println("databaseOK"+ds);

    conn=ds.getConnection();

    if(conn!=null){

    stmt=conn.createStatement();

    //System.out.println("ConnOK:"+stmt);

    }

    }

    }catch(Exceptione){

    e.printStackTrace();

    }

    }

    /*******************

    *执行sql语句,用于insert

    *****************/

    publicbooleanExcuteSQL(Stringsql)

    {

    try

    {

    //System.out.println("sql:"+sql);

    returnstmt.execute(sql);

    }

    catch(Exceptione)

    {

    e.printStackTrace();

    }

    returnfalse;

    }

    /*******************

    *查询sql语句,用于select

    *****************/

    publicvoidSQLQuery(Stringsql)

    {

    try

    {

    rst=stmt.executeQuery(sql);

    }

    catch(Exceptione)

    {

    e.printStackTrace();

    }

    return;

    }

    /*******************

    *更新的sql语句,用于Update

    *****************/

    publicintSQLUpdate(Stringsql)

    {

    try

    {

    returnstmt.executeUpdate(sql);

    }

    catch(Exceptione)

    {

    e.printStackTrace();

    }

    return0;

    }

    /**************

    *关闭连接

    ***************/

    publicintCloseConn()

    {

    try{

    if(rst!=null){

    try{rst.close();}

    catch(SQLExceptione)

    {System.out.print("rescolsetwice");}

    rst=null;

    }

    stmt.close();

    stmt=null;

    conn.close();//Returntoconnectionpool

    conn=null;//Makesurewedon-tcloseittwice

    }catch(SQLExceptione){

    System.out.println("CloseConnError");

    }finally{

    //Alwaysmakesureresultsetsandstatementsareclosed,

    //andtheconnectionisreturnedtothepool

    if(rst!=null){

    try{rst.close();}

    catch(SQLExceptione)

    {System.out.print("rescolsetwice");}

    rst=null;

    }

    if(stmt!=null){

    try{stmt.close();}catch(SQLExceptione){;}

    stmt=null;

    }

    if(conn!=null){

    try{conn.close();}catch(SQLExceptione){;}

    conn=null;

    }

    }

    return1;

    }

    /****************

    *获得Statement

    ****************/

    publicStatementGetStatement()

    {

    returnstmt;

    }

    }
  为了方便下次访问,请牢记闪文书库网址www.shanwen.com,您的支持是我们最大的动力。注册会员
|
|
|
|
闪文书库,收录精品小说。请点击到书库论坛推荐你要看的书,我们收录 加入书架书签 | 推荐本书 | 打开书架 | 阅读目录 | 返回书页 |  Top ↑
作品本身仅代表作者本人的观点,与闪文书库立场无关。阅读者如发现作品内容确有与法律抵触之处,可向闪文书库举报
如有章节错误、排版不齐或版权疑问、作品内容有违相关法律等请至闪文客服举报论坛举报,可获加分奖励
Copyright (C) 2007 Www.Shanwen.Com 闪文书库 All Rights Reserved