快速业务通道

Jbuilder6.0+Weblogic6.0完成EJB开发部署 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-23
paraValue; public void init(){ try{ initCtx= new InitialContext(); DataSource ds = (javax.sql.DataSource) initCtx.lookup("DBSource"); con= ds.getConnection(); System.out.println("connection = "+con); }catch(Exception e){System.out.println(e);} } /* //设置SQLContext的类名; public void setSqlContext(String str){ sqlContext = str; } */ private void initSQLContext(){ init(); try{ Class aclass= Class.forName(sqlContext); sql = (defaultSQLContext)aclass.newInstance(); }catch (Exception e){ System.out.println("cannot initialize instance"+sqlContext); System.out.println(e); } } /* public void setParaValue(String[] str){ this.paraValue = str; } */ public void execute(){ String[] paraType; int iColumnCount = 0; ResultSet rs = null; ResultSetMetaData rsm= null; Vector vInnerValue; //首先获得SQLContext; initSQLContext(); try{ PreparedStatement ps = con.prepareStatement(sql.getSQL()); System.out.println("SQL = "+sql.getSQL()); if(sql.getParameterType()!=null&¶Value!=null) { paraType = sql.getParameterType(); for(int i=0;i { if(paraType[i].equalsIgnoreCase("varchar")||paraType[i].equalsIgnoreCase("varchar2")) ps.setString(i+1,paraValue[i].trim()); else if(paraType[i].equalsIgnoreCase("integer")||paraType[i].equalsIgnoreCase("int")) ps.setInt(i+1,Integer.parseInt(paraValue[i].trim())); else if(paraType[i].equalsIgnoreCase("long")) ps.setLong(i+1,Long.parseLong(paraValue[i].trim())); else if(paraType[i].equalsIgnoreCase("date")) ps.setDate(i+1,java.sql.Date.valueOf(paraValue[i].trim())); else if(paraType[i].equalsIgnoreCase("boolean")) ps.setBoolean(i+1,Boolean.getBoolean(paraValue[i].trim())); else if(paraType[i].equalsIgnoreCase("double")) ps.setDouble(i+1,Double.parseDouble(paraValue[i].trim())); else ps.setString(i+1,paraValue[i].trim()); System.out.print("ParameterType["+i+"] = "+paraType[i]); System.out.println(" ParameterValue["+i+"] = "+paraValue[i]); }//end for }//end if if(sql.getType()==0) //查询; { vResult = new Vector(); System.out.println("execute Query!"); rs = ps.executeQuery(); rsm= rs.getMetaData(); iColumnCount= rsm.getColumnCount(); while(rs.next()){ vInnerValue= new Vector(); for(int j=1;j<=iColumnCount;j++) { Object o = rs.getObject(j); if(o==null) vInnerValue.addElement(""); else vInnerValue.addElement(o.toString()); }//end for vResult.addElement(vInnerValue); }//end while vColumnName = new Vector(); //获得字段名; for(int i=1;i<=iColumnCount;i++) vColumnName.addElement(rsm.getColumnName(i)); }//end if 查询; else if(sql.getType()==1) //更新语句; { try{ System.out.println("execute Update!"); iReturn = ps.executeUpdate(); con.commit(); }catch(Exception ex) { iReturn=0; con.rollback(); System.out.println("update ejb error!"+ex); } } ps.close(); }catch (Exception ne){ System.out.println(ne); } } public Vector getQueryResult(){

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号