您现在的位置是:首页 >

c语言环境配置 Eclipse下配置swt开发环境

火烧 2021-11-12 00:27:24 1054
Ecli e下配置 wt开发环境   创建存储过程的脚本  使用 ql erver 中的 u 数据库中的 jo 表为例    create rocedure howAll a elect * from

Eclipse下配置swt开发环境  

  创建存储过程的脚本

  使用sqlserver 中的pubs 数据库中的 jobs表为例

      create procedure  showAll    as    select * from jobs

  create procedure obtainJob_desc    @outputParam varchar( ) output     @id          int    as    select @outputParam = job_desc from jobs where job_id = @id

  create procedure obtainReturn    as    declare @ret int    select @ret = count(*) from jobs    return @ret

  declare @ret int    exec  @ret = obtainReturn    print @ret

      用来获得连接的函数    public  Connection getConnection() {      Connection con = null;      try {       Class forName( microsoft jdbc sqlserver SQLServerDriver );       con = DriverManager getConnection( jdbc:microsoft:sqlserver://localhost: ;databasename=pubs sa );      } catch (Exception e) {       e printStackTrace();      }      return con ;     }    调用得到结果集的存储过程

c语言环境配置 Eclipse下配置swt开发环境

    public void getResultSet() {            //获得连接            Connection con = this getConnection();            try {                //showAll为存储过程名                java sql CallableStatement cstm = con prepareCall( {call showAll } );                ResultSet rs = cstm executeQuery();                while(rs next()) {                    //这里写逻辑代码                     System out println(rs getString( ));                }                rs close();                con close();            } catch (SQLException e) {                // TODO Auto generated catch block                e printStackTrace();            }

  }

   调用带有 输入 输出 参数的存储过程

     public void getOutParameter(int inParam) {            String outParam;            Connection con = this getConnection();

  try {                CallableStatement cstm = con prepareCall( {call obtainJob_desc (? ?)} );                cstm registerOutParameter( Types VARCHAR);                cstm setInt( inParam);                cstm execute();;

  //得到输出参数                 String outParma = cstm getString( );                System out println(outParma);                cstm close();                con close();

  } catch (SQLException e) {                // TODO Auto generated catch block                e printStackTrace();            }

  }

    调用带返回值的存储过程

    public void getReturn() {            int ret;            Connection con = this getConnection();            try {                CallableStatement cstm = con prepareCall( {?=call obtainReturn()} );                cstm registerOutParameter( Types INTEGER);

  cstm execute();                //得到返回值                 ret = cstm getInt( );

  System out println(ret);                cstm close();                con close();

  } catch (SQLException e) {                // TODO Auto generated catch block                e printStackTrace();            }

  }

lishixinzhi/Article/program/Java/ky/201311/28246  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码