最新评论
Re:困惑?UML的缺陷? flyingbugs 2009-12-26 13:28
UML在描述行业业务逻辑的时候,特别是银行业务,远不如普通的流程图与数据流图。
re: 5月以来的学习,软件工程+设计模式+J2EE开发+portal开发,以及SOA技术 灵石 2008-01-15 11:20
没想到,1年半没回来,竟是这个邮件把我拉回到博客来
最先是想,1年半之前我写什么了,能在一年半后收到这样的评价?
本着好奇回来看看,现在只有1个表情:笑了
最先是想,1年半之前我写什么了,能在一年半后收到这样的评价?
本着好奇回来看看,现在只有1个表情:笑了
真有意思 中科院研究生院 2008-01-07 09:18
看到你这篇文章又让我想起大师与愚人的故事了, 一门语言经是那么多工程师专家历经了那么多年开发设计。 融合了那么多技术领域的知识。 你区区几个月就学精通了, 我做了3年J2EE都不敢说,中科院连个博士都不敢说的大话从你嘴里说出来怎么就那么别扭呢。 可见是在外面上的培训班学的计算机吧。 唉可悲,我们国人的怎么都那么浮躁, 学习了一点知识怎么就这样卖弄。可悲呀,可悲
re: 学习程序开发的方法,仅供参考吧 路过 2007-12-11 10:55
有同感
re: 5月以来的学习,软件工程+设计模式+J2EE开发+portal开发,以及SOA技术 的 2007-11-09 17:49
楼主看归看,想证明你理解了吗?自己做个WEB框架出来.再说
re: 代码实现JSF组件树的创建与呈现[未登录] 和尚 2007-07-24 11:41
这是sun jsf api 中的一段
encodeBegin
public abstract void encodeBegin(ontFacesContext cext)
throws java.io.IOException
If our rendered property is true, render the beginning of the current state of this UIComponent to the response contained in the specified FacesContext.
If a Renderer is associated with this UIComponent, the actual encoding will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).
Parameters:
context - FacesContext for the response we are creating
Throws:
java.io.IOException - if an input/output error occurs while rendering
java.lang.NullPointerException - if context is null
如果FacesContext为null时会抛java.lang.NullPointerException
但是我在程序中对FacesContext做了判断,FacesContext不为null时也抛了
java.lang.NullPointerException异常,郁闷啊!
encodeBegin
public abstract void encodeBegin(ontFacesContext cext)
throws java.io.IOException
If our rendered property is true, render the beginning of the current state of this UIComponent to the response contained in the specified FacesContext.
If a Renderer is associated with this UIComponent, the actual encoding will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).
Parameters:
context - FacesContext for the response we are creating
Throws:
java.io.IOException - if an input/output error occurs while rendering
java.lang.NullPointerException - if context is null
如果FacesContext为null时会抛java.lang.NullPointerException
但是我在程序中对FacesContext做了判断,FacesContext不为null时也抛了
java.lang.NullPointerException异常,郁闷啊!
re: 代码实现JSF组件树的创建与呈现[未登录] 和尚 2007-07-24 09:49
调试不成功啊,在树呈现的时候报错!
Caused by: java.lang.NullPointerException
at org.apache.myfaces.renderkit.html.HtmlFormRendererBase.encodeBegin(HtmlFormRendererBase.java:62)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:312)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.renderResponse(Newpage.java:52)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.renderResponse(Newpage.java:57)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.pageLoad(Newpage.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
... 37 more
这是什么问题啊!
Caused by: java.lang.NullPointerException
at org.apache.myfaces.renderkit.html.HtmlFormRendererBase.encodeBegin(HtmlFormRendererBase.java:62)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:312)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.renderResponse(Newpage.java:52)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.renderResponse(Newpage.java:57)
at cn.ccb.odsbmetric.metric.web.bb.Newpage.pageLoad(Newpage.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
... 37 more
这是什么问题啊!
路过感言 达到 2007-04-10 10:28
你真是天才啊,一个月学习这么多东西,还能感悟到他们的精髓,我在学校混了N年了,这些课程都学了,一切都停留在表面,不说怎么设计应用,连个语意都没理解清楚.实在是很悲哀啊,明明想学,也认真在听,但就听不明白.几百万有志青年就是这样被学校的制度和管理给废掉了,真羡慕你们这些已经事业有成,知识渊博的高人!
re: 代码实现JSF组件树的创建与呈现 jmzwcn@msn.com 2007-02-08 11:17
root.getChildren().clear();每次都执行这个方法后,myComponet.setValue("aaa")就好用了呀
re: UML学习随笔20060420 scotoma 2006-12-28 13:38
看了体会到不少的东西..支持下.
re: 读博友的一篇《陈安之成功法则》后的感想 flower 2006-11-19 18:57
你有颗平静的心,能平静地对待周遭的事情,有泰然处之的大将风度,也是我要学习的榜样!
re: 精神空虚时想到的 someone[匿名] 2006-09-29 21:21
兄弟的感觉挺能体会的,还是扩大圈子,多交好朋友吧
re: 我对j2EE传统持久层方式的改变 灵石 2006-09-25 11:24
这篇文章今天我再来看,对他做了大的修改,
以前我认为是对传统持久层的改变,现在跳出局来看,应该是在持久层与应用层分别引入新的技术后的发展。
现在已经改了,现在描述得应该比以前准确些了
以前我认为是对传统持久层的改变,现在跳出局来看,应该是在持久层与应用层分别引入新的技术后的发展。
现在已经改了,现在描述得应该比以前准确些了
re: 代码实现JSF组件树的创建与呈现 灵石 2006-09-11 09:17
这一点我没有讲清楚,因为我以为大家应该都明白的,所以没有提
=========================================
我是这样做的,jsp页面对应一个request域的bean
在bean里创建一个pageLoad()的方法,实现组件树组织与呈现
在jsp页面这样调用:
<f:view>
先写一个faces output组件,引用一个""值显示,否则后面那一句不可用
//现在可写这句了:pc_First_page为页面faces受管的bean名字,pagecode.First_page为bean类名,配置文件里定义的.
<% ((pagecode.First_page)request.getAttribut("pc_First_page")).pageLoad() %>
</f:view>
=========================================
我是这样做的,jsp页面对应一个request域的bean
在bean里创建一个pageLoad()的方法,实现组件树组织与呈现
在jsp页面这样调用:
<f:view>
先写一个faces output组件,引用一个""值显示,否则后面那一句不可用
//现在可写这句了:pc_First_page为页面faces受管的bean名字,pagecode.First_page为bean类名,配置文件里定义的.
<% ((pagecode.First_page)request.getAttribut("pc_First_page")).pageLoad() %>
</f:view>
re: 代码实现JSF组件树的创建与呈现 Coffee[匿名] 2006-09-09 09:31
==发错了,改一下==
======jsp======
<f:view>
<h:form id="regularMeetingDataForm">
<h:panelGrid columns="10" id="regularMeetingDataPanel"></h:panelGrid>
<h:commandButton value="TEST"
styleClass="button1" actionListener="#{testPage.getPage}">
</h:commandButton>
</h:form>
</f:view>
======jsp======
<f:view>
<h:form id="regularMeetingDataForm">
<h:panelGrid columns="10" id="regularMeetingDataPanel"></h:panelGrid>
<h:commandButton value="TEST"
styleClass="button1" actionListener="#{testPage.getPage}">
</h:commandButton>
</h:form>
</f:view>
re: 代码实现JSF组件树的创建与呈现 Coffee[匿名] 2006-09-09 09:23
如何在页面中调用呢?我的理解可能有严重错误,请指教谢谢
==============
======jsp======
<f:view>
<h:form id="regularMeetingDataForm">
<h:panelGrid columns="10" id="regularMeetingDataPanel"></h:panelGrid>
<h:commandButton value="TEST"
styleClass="button1" actionListener="#{testPage.ListRMeetings}">
</h:commandButton>
</h:form>
</f:view>
================
=====java========
public void getPage(){
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
UIPanel panel = (UIPanel) root.findComponent("regularMeetingDataForm").findComponent("regularMeetingDataPanel");
UIOutput myText2 = new UIOutput();
myText2.setId("myText2");
myText2.setValue("Hello");
panel.getChildren().add(myText2);
renderResponse(facesContext, root) ; //呈现整个组件树
}
==============
======jsp======
<f:view>
<h:form id="regularMeetingDataForm">
<h:panelGrid columns="10" id="regularMeetingDataPanel"></h:panelGrid>
<h:commandButton value="TEST"
styleClass="button1" actionListener="#{testPage.ListRMeetings}">
</h:commandButton>
</h:form>
</f:view>
================
=====java========
public void getPage(){
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();
UIPanel panel = (UIPanel) root.findComponent("regularMeetingDataForm").findComponent("regularMeetingDataPanel");
UIOutput myText2 = new UIOutput();
myText2.setId("myText2");
myText2.setValue("Hello");
panel.getChildren().add(myText2);
renderResponse(facesContext, root) ; //呈现整个组件树
}
re: 困惑?UML的缺陷? 马铭 2006-09-05 19:47
呵呵,用例图在和客户交流的时候很有用的。
re: 5月以来的学习,软件工程+设计模式+J2EE开发+portal开发,以及SOA技术 灵石 2006-08-18 00:17
j2ee的知识点多,WebServises,javabean,servlet,JSP,EJB,JMS,应用客户机,Struts,JSF,Spring,EGL,基本Portlet与JSF Portlet,以及websohere应用服务配置与接口,还有很多很多,反正在标准之下,发展出来了很多的技术、产品、知识点。
但对于软件开发人员的我们来说,我们就好像建筑设计师,而所有上面提到的或者更多的都只是我们可选的材料而已,我们需要了解其发展历史,以及深入的原理和环境需求,就像建筑设计师了解材料的特性和适用环境一样,才能以最少的成本设计出最好的建筑,而建筑师设计方法经验的沉淀,就好比软件学上的设计模式。
关于设计,哈哈,随着最近在开发上的如鱼得水,得心应手,真的感觉自己是个天才了,最让我自豪的是设计模式在我手里活了,不再是书本上一个个死板规则的UML图形,用的是其神而不是其形,而且也不再是各自独立的模式,在我的实际应用中,他们相互依存,你中有我,我中有你,共同构成我的设计,而且代码量没有变多,变得更规范,更少了。
我想设计师之间的讨论应该是设计经验的讨论,再附带的提到当前什么先进的技术、产品出现了,可以这样做我们的设计了,等等。。。
但对于软件开发人员的我们来说,我们就好像建筑设计师,而所有上面提到的或者更多的都只是我们可选的材料而已,我们需要了解其发展历史,以及深入的原理和环境需求,就像建筑设计师了解材料的特性和适用环境一样,才能以最少的成本设计出最好的建筑,而建筑师设计方法经验的沉淀,就好比软件学上的设计模式。
关于设计,哈哈,随着最近在开发上的如鱼得水,得心应手,真的感觉自己是个天才了,最让我自豪的是设计模式在我手里活了,不再是书本上一个个死板规则的UML图形,用的是其神而不是其形,而且也不再是各自独立的模式,在我的实际应用中,他们相互依存,你中有我,我中有你,共同构成我的设计,而且代码量没有变多,变得更规范,更少了。
我想设计师之间的讨论应该是设计经验的讨论,再附带的提到当前什么先进的技术、产品出现了,可以这样做我们的设计了,等等。。。
...续。。。。。。。。。。。。。。。。。。。。。 灵石 2006-08-08 16:00
第四部分(应用配置与授权)
...续。。。。。。。。。。。。。。。。。。。。。 灵石 2006-08-08 15:58
第三部分(自定义用户注册接口实现代码)
import java.rmi.RemoteException;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.List;
import java.util.Properties;
import com.ibm.websphere.security.CertificateMapFailedException;
import com.ibm.websphere.security.CertificateMapNotSupportedException;
import com.ibm.websphere.security.CustomRegistryException;
import com.ibm.websphere.security.EntryNotFoundException;
import com.ibm.websphere.security.NotImplementedException;
import com.ibm.websphere.security.PasswordCheckFailedException;
import com.ibm.websphere.security.Result;
import com.ibm.websphere.security.UserRegistry;
import com.ibm.websphere.security.cred.WSCredential;
import com.ibm.websphere.security.CertificateMapNotSupportedException;
import com.ibm.websphere.security.CustomRegistryException;
import com.ibm.websphere.security.EntryNotFoundException;
import com.ibm.websphere.security.NotImplementedException;
import com.ibm.websphere.security.PasswordCheckFailedException;
import com.ibm.websphere.security.Result;
import com.ibm.websphere.security.UserRegistry;
import com.ibm.websphere.security.cred.WSCredential;
/*
* 创建日期 2006-7-11
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
* 创建日期 2006-7-11
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author 灵石
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class LoginValidation implements UserRegistry {
* @author 灵石
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class LoginValidation implements UserRegistry {
/** Default Constructor * */
public LoginValidation() throws java.rmi.RemoteException {
}
public LoginValidation() throws java.rmi.RemoteException {
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#initialize(java.util.Properties)
*/
public void initialize(Properties arg0) throws CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#initialize(java.util.Properties)
*/
public void initialize(Properties arg0) throws CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#checkPassword(java.lang.String,
* java.lang.String)
*/
public String checkPassword(String userSecurityName, String passwd)
throws PasswordCheckFailedException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String userName = null;
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#checkPassword(java.lang.String,
* java.lang.String)
*/
public String checkPassword(String userSecurityName, String passwd)
throws PasswordCheckFailedException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String userName = null;
String sqlStr = "select * from loginer where login='"
+ userSecurityName + "' and password='" + passwd + "'";
+ userSecurityName + "' and password='" + passwd + "'";
if (userSecurityName.equals("supadmin")) {
sqlStr = "select * from supersysadmin where password='" + passwd
+ "'";
}
sqlStr = "select * from supersysadmin where password='" + passwd
+ "'";
}
try {
if (DbOperate.getsqlcount(sqlStr) >= 1) {
userName = userSecurityName;
System.out.println(" checkPassword succeed for "
+ userSecurityName);
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
if (DbOperate.getsqlcount(sqlStr) >= 1) {
userName = userSecurityName;
System.out.println(" checkPassword succeed for "
+ userSecurityName);
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
if (userName == null) {
throw new PasswordCheckFailedException(
"Password check failed for user: " + userSecurityName);
}
throw new PasswordCheckFailedException(
"Password check failed for user: " + userSecurityName);
}
return userName;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#mapCertificate(java.security.cert.X509Certificate[])
*/
public String mapCertificate(X509Certificate[] cert)
throws CertificateMapNotSupportedException,
CertificateMapFailedException, CustomRegistryException,
RemoteException {
//TODO 自动生成方法存根
String name = null;
X509Certificate cert1 = cert[0];
try {
// map the SubjectDN in the certificate to a userID.
name = cert1.getSubjectDN().getName();
} catch (Exception ex) {
throw new CertificateMapNotSupportedException(ex.getMessage(), ex);
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#mapCertificate(java.security.cert.X509Certificate[])
*/
public String mapCertificate(X509Certificate[] cert)
throws CertificateMapNotSupportedException,
CertificateMapFailedException, CustomRegistryException,
RemoteException {
//TODO 自动生成方法存根
String name = null;
X509Certificate cert1 = cert[0];
try {
// map the SubjectDN in the certificate to a userID.
name = cert1.getSubjectDN().getName();
} catch (Exception ex) {
throw new CertificateMapNotSupportedException(ex.getMessage(), ex);
}
if (!isValidUser(name)) {
throw new CertificateMapFailedException("user: " + name
+ " is not valid");
}
return name;
}
throw new CertificateMapFailedException("user: " + name
+ " is not valid");
}
return name;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getRealm()
*/
public String getRealm() throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
String name = "customRealm";
return name;
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getRealm()
*/
public String getRealm() throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
String name = "customRealm";
return name;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUsers(java.lang.String,
* int)
*/
public Result getUsers(String pattern, int limit)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
List allUsers = new ArrayList();
Result result = new Result();
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUsers(java.lang.String,
* int)
*/
public Result getUsers(String pattern, int limit)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
List allUsers = new ArrayList();
Result result = new Result();
try {
if (match("supadmin", pattern) && limit > 0) {
allUsers.add("supadmin");
limit--;
}
List list = DbOperate
.executeQuery("select LOGIN from LOGINER order by LOGIN");
int i = 0;
for (i = 0; i < list.size() && limit > 0; i++) {
Map map = (Map) list.get(i);
if (match(map.get("LOGIN").toString(), pattern)) {
allUsers.add(map.get("LOGIN"));
limit--;
}
}
System.out.println(i);
if (i < list.size())
result.setHasMore();
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
if (match("supadmin", pattern) && limit > 0) {
allUsers.add("supadmin");
limit--;
}
List list = DbOperate
.executeQuery("select LOGIN from LOGINER order by LOGIN");
int i = 0;
for (i = 0; i < list.size() && limit > 0; i++) {
Map map = (Map) list.get(i);
if (match(map.get("LOGIN").toString(), pattern)) {
allUsers.add(map.get("LOGIN"));
limit--;
}
}
System.out.println(i);
if (i < list.size())
result.setHasMore();
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
result.setList(allUsers);
return result;
}
return result;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUserDisplayName(java.lang.String)
*/
public String getUserDisplayName(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String displayName = null;
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUserDisplayName(java.lang.String)
*/
public String getUserDisplayName(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String displayName = null;
if (!isValidUser(userSecurityName)) {
EntryNotFoundException nsee = new EntryNotFoundException("user: "
+ userSecurityName + " is not valid");
throw nsee;
}
EntryNotFoundException nsee = new EntryNotFoundException("user: "
+ userSecurityName + " is not valid");
throw nsee;
}
try {
displayName = userSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
displayName = userSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return displayName;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueUserId(java.lang.String)
*/
public String getUniqueUserId(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String uniqueUsrId = null;
try {
if (isValidUser(userSecurityName)) {
uniqueUsrId = userSecurityName;
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueUserId(java.lang.String)
*/
public String getUniqueUserId(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String uniqueUsrId = null;
try {
if (isValidUser(userSecurityName)) {
uniqueUsrId = userSecurityName;
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
if (uniqueUsrId == null) {
EntryNotFoundException nsee = new EntryNotFoundException(
"Cannot obtain uniqueId for user: " + userSecurityName);
throw nsee;
}
return uniqueUsrId;
}
EntryNotFoundException nsee = new EntryNotFoundException(
"Cannot obtain uniqueId for user: " + userSecurityName);
throw nsee;
}
return uniqueUsrId;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUserSecurityName(java.lang.String)
*/
public String getUserSecurityName(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String usrSecName = null;
try {
if (isValidUser(userSecurityName)) {
usrSecName = userSecurityName;
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUserSecurityName(java.lang.String)
*/
public String getUserSecurityName(String userSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String usrSecName = null;
try {
if (isValidUser(userSecurityName)) {
usrSecName = userSecurityName;
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
if (usrSecName == null) {
EntryNotFoundException nsee = new EntryNotFoundException(
"Cannot obtain uniqueId for user: " + userSecurityName);
throw nsee;
}
return usrSecName;
}
EntryNotFoundException nsee = new EntryNotFoundException(
"Cannot obtain uniqueId for user: " + userSecurityName);
throw nsee;
}
return usrSecName;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#isValidUser(java.lang.String)
*/
public boolean isValidUser(String userSecurityName)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
boolean isValid = false;
try {
if (userSecurityName.equals("supadmin"))
isValid = true;
String sqlStr = "select * from loginer where login='"
+ userSecurityName + "'";
if (DbOperate.getsqlcount(sqlStr) >= 1)
isValid = true;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#isValidUser(java.lang.String)
*/
public boolean isValidUser(String userSecurityName)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
boolean isValid = false;
try {
if (userSecurityName.equals("supadmin"))
isValid = true;
String sqlStr = "select * from loginer where login='"
+ userSecurityName + "'";
if (DbOperate.getsqlcount(sqlStr) >= 1)
isValid = true;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return isValid;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroups(java.lang.String,
* int)
*/
public Result getGroups(String pattern, int limit)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
List allGroups = new ArrayList();
Result result = new Result();
int count = 0, i = 0;
try {
if (limit > count) {
i++;
if (match("SuperSysAdmin", pattern)) {
allGroups.add("SuperSysAdmin");
count++;
}
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroups(java.lang.String,
* int)
*/
public Result getGroups(String pattern, int limit)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
List allGroups = new ArrayList();
Result result = new Result();
int count = 0, i = 0;
try {
if (limit > count) {
i++;
if (match("SuperSysAdmin", pattern)) {
allGroups.add("SuperSysAdmin");
count++;
}
}
if (limit > count) {
i++;
if (match("Admin", pattern)) {
allGroups.add("Admin");
count++;
}
}
i++;
if (match("Admin", pattern)) {
allGroups.add("Admin");
count++;
}
}
if (limit > count) {
i++;
if (match("InUser", pattern)) {
allGroups.add("InUser");
count++;
}
}
i++;
if (match("InUser", pattern)) {
allGroups.add("InUser");
count++;
}
}
if (limit > count) {
i++;
if (match("OutPermUser", pattern)) {
allGroups.add("OutPermUser");
count++;
}
}
i++;
if (match("OutPermUser", pattern)) {
allGroups.add("OutPermUser");
count++;
}
}
if (limit > count) {
i++;
if (match("OutNetUser", pattern)) {
allGroups.add("OutNetUser");
count++;
}
}
i++;
if (match("OutNetUser", pattern)) {
allGroups.add("OutNetUser");
count++;
}
}
List list = DbOperate
.executeQuery("select GROUPKEY from GROUPS order by GROUPTYPE,GROUPKEY");
int j = 0;
for (j = 0; j < list.size() && limit > 0; j++) {
Map map = (Map) list.get(j);
if (match(map.get("GROUPKEY").toString(), pattern)) {
allGroups.add(map.get("GROUPKEY"));
limit--;
}
}
.executeQuery("select GROUPKEY from GROUPS order by GROUPTYPE,GROUPKEY");
int j = 0;
for (j = 0; j < list.size() && limit > 0; j++) {
Map map = (Map) list.get(j);
if (match(map.get("GROUPKEY").toString(), pattern)) {
allGroups.add(map.get("GROUPKEY"));
limit--;
}
}
if (i < 5)
result.setHasMore();
else {
if (j < list.size())
result.setHasMore();
}
result.setHasMore();
else {
if (j < list.size())
result.setHasMore();
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
result.setList(allGroups);
return result;
}
return result;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupDisplayName(java.lang.String)
*/
public String getGroupDisplayName(String groupSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String displayName = null;
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupDisplayName(java.lang.String)
*/
public String getGroupDisplayName(String groupSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String displayName = null;
if (!isValidGroup(groupSecurityName)) {
EntryNotFoundException nsee = new EntryNotFoundException("group: "
+ groupSecurityName + " is not valid");
throw nsee;
}
try {
displayName = groupSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
EntryNotFoundException nsee = new EntryNotFoundException("group: "
+ groupSecurityName + " is not valid");
throw nsee;
}
try {
displayName = groupSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return displayName;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueGroupId(java.lang.String)
*/
public String getUniqueGroupId(String groupSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String uniqueGrpId = null;
if (!isValidGroup(groupSecurityName))
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueGroupId(java.lang.String)
*/
public String getUniqueGroupId(String groupSecurityName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
String uniqueGrpId = null;
if (!isValidGroup(groupSecurityName))
if (!isValidGroup(groupSecurityName)) {
EntryNotFoundException nsee = new EntryNotFoundException(
"group: " + groupSecurityName + " is not valid");
throw nsee;
}
try {
uniqueGrpId = groupSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
EntryNotFoundException nsee = new EntryNotFoundException(
"group: " + groupSecurityName + " is not valid");
throw nsee;
}
try {
uniqueGrpId = groupSecurityName;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return uniqueGrpId;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueGroupIds(java.lang.String)
*/
public List getUniqueGroupIds(String uniqueUserId)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
List uniqueGrpIds = new ArrayList();
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUniqueGroupIds(java.lang.String)
*/
public List getUniqueGroupIds(String uniqueUserId)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
List uniqueGrpIds = new ArrayList();
try {
if (uniqueUserId.equals("supadmin"))
uniqueGrpIds.add("SuperSysAdmin");
else {
List list = DbOperate
.executeQuery("select LINKTABLE from LOGINER where LOGIN='"
+ uniqueUserId + "'");
if (list.size() > 0) {
Map map = (Map) list.get(0);
uniqueGrpIds.add(map.get("LINKTABLE"));
}
if (uniqueUserId.equals("supadmin"))
uniqueGrpIds.add("SuperSysAdmin");
else {
List list = DbOperate
.executeQuery("select LINKTABLE from LOGINER where LOGIN='"
+ uniqueUserId + "'");
if (list.size() > 0) {
Map map = (Map) list.get(0);
uniqueGrpIds.add(map.get("LINKTABLE"));
}
List list2 = DbOperate
.executeQuery("select GROUPKEY from USERSGROUPS where LOGIN='"
+ uniqueUserId + "'");
for (int i = 0; i < list.size(); i++) {
Map map = (Map) list.get(i);
uniqueGrpIds.add(map.get("GROUPKEY"));
}
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
.executeQuery("select GROUPKEY from USERSGROUPS where LOGIN='"
+ uniqueUserId + "'");
for (int i = 0; i < list.size(); i++) {
Map map = (Map) list.get(i);
uniqueGrpIds.add(map.get("GROUPKEY"));
}
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return uniqueGrpIds;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupSecurityName(java.lang.String)
*/
public String getGroupSecurityName(String uniqueGroupId)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
String grpSecName = null;
grpSecName = uniqueGroupId;
// TODO 自动生成方法存根
return grpSecName;
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupSecurityName(java.lang.String)
*/
public String getGroupSecurityName(String uniqueGroupId)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
String grpSecName = null;
grpSecName = uniqueGroupId;
// TODO 自动生成方法存根
return grpSecName;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#isValidGroup(java.lang.String)
*/
public boolean isValidGroup(String groupSecurityName)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
boolean isValid = false;
try {
if (groupSecurityName.equals("SuperSysAdmin"))
isValid = true;
else if (groupSecurityName.equals("Admin"))
isValid = true;
else if (groupSecurityName.equals("InUser"))
isValid = true;
else if (groupSecurityName.equals("OutPermUser"))
isValid = true;
else if (groupSecurityName.equals("OutNetUser"))
isValid = true;
else if (DbOperate
.getsqlcount("select * from GROUPS where GROUPKEY='"
+ groupSecurityName + "'") >= 1)
isValid = true;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#isValidGroup(java.lang.String)
*/
public boolean isValidGroup(String groupSecurityName)
throws CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
boolean isValid = false;
try {
if (groupSecurityName.equals("SuperSysAdmin"))
isValid = true;
else if (groupSecurityName.equals("Admin"))
isValid = true;
else if (groupSecurityName.equals("InUser"))
isValid = true;
else if (groupSecurityName.equals("OutPermUser"))
isValid = true;
else if (groupSecurityName.equals("OutNetUser"))
isValid = true;
else if (DbOperate
.getsqlcount("select * from GROUPS where GROUPKEY='"
+ groupSecurityName + "'") >= 1)
isValid = true;
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return isValid;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupsForUser(java.lang.String)
*/
public List getGroupsForUser(String userName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
List grpsForUser = new ArrayList();
try {
if (userName.equals("supadmin"))
grpsForUser.add("SuperSysAdmin");
else {
List list = DbOperate
.executeQuery("select LINKTABLE from LOGINER where LOGIN='"
+ userName + "'");
if (list.size() > 0) {
Map map = (Map) list.get(0);
grpsForUser.add(map.get("LINKTABLE"));
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getGroupsForUser(java.lang.String)
*/
public List getGroupsForUser(String userName)
throws EntryNotFoundException, CustomRegistryException,
RemoteException {
// TODO 自动生成方法存根
List grpsForUser = new ArrayList();
try {
if (userName.equals("supadmin"))
grpsForUser.add("SuperSysAdmin");
else {
List list = DbOperate
.executeQuery("select LINKTABLE from LOGINER where LOGIN='"
+ userName + "'");
if (list.size() > 0) {
Map map = (Map) list.get(0);
grpsForUser.add(map.get("LINKTABLE"));
}
List list2 = DbOperate
.executeQuery("select GROUPKEY from USERSGROUPS where LOGIN='"
+ userName + "'");
for (int i = 0; i < list.size(); i++) {
Map map = (Map) list.get(i);
grpsForUser.add(map.get("GROUPKEY"));
}
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
.executeQuery("select GROUPKEY from USERSGROUPS where LOGIN='"
+ userName + "'");
for (int i = 0; i < list.size(); i++) {
Map map = (Map) list.get(i);
grpsForUser.add(map.get("GROUPKEY"));
}
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
return grpsForUser;
}
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUsersForGroup(java.lang.String,
* int)
*/
public Result getUsersForGroup(String groupSecurityName, int limit)
throws NotImplementedException, EntryNotFoundException,
CustomRegistryException, RemoteException {
// TODO 自动生成方法存根..................
List usrsForGroup = new ArrayList();
Result result = new Result();
try {
if (groupSecurityName.equals("SuperSysAdmin")) {
if (limit > 0)
usrsForGroup.add("supadmin");
} else {
String sqlStr = null;
if (groupSecurityName.equals("Admin")
|| groupSecurityName.equals("InUser")
|| groupSecurityName.equals("OutNetUser")
|| groupSecurityName.equals("OutPermUser")) {
sqlStr = "select LOGIN from LOGINER where LINKTABLE='"
+ groupSecurityName + "'";
} else {
sqlStr = "select LOGIN from USERSGROUPS where GROUPKEY='"
+ groupSecurityName + "'";
}
List list = DbOperate.executeQuery(sqlStr);
int i = 0;
for (i = 0; i < list.size() && limit > 0; i++) {
Map map = (Map) list.get(i);
usrsForGroup.add(map.get("LOGIN"));
limit--;
}
System.out.println(i);
if (i < list.size())
result.setHasMore();
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#getUsersForGroup(java.lang.String,
* int)
*/
public Result getUsersForGroup(String groupSecurityName, int limit)
throws NotImplementedException, EntryNotFoundException,
CustomRegistryException, RemoteException {
// TODO 自动生成方法存根..................
List usrsForGroup = new ArrayList();
Result result = new Result();
try {
if (groupSecurityName.equals("SuperSysAdmin")) {
if (limit > 0)
usrsForGroup.add("supadmin");
} else {
String sqlStr = null;
if (groupSecurityName.equals("Admin")
|| groupSecurityName.equals("InUser")
|| groupSecurityName.equals("OutNetUser")
|| groupSecurityName.equals("OutPermUser")) {
sqlStr = "select LOGIN from LOGINER where LINKTABLE='"
+ groupSecurityName + "'";
} else {
sqlStr = "select LOGIN from USERSGROUPS where GROUPKEY='"
+ groupSecurityName + "'";
}
List list = DbOperate.executeQuery(sqlStr);
int i = 0;
for (i = 0; i < list.size() && limit > 0; i++) {
Map map = (Map) list.get(i);
usrsForGroup.add(map.get("LOGIN"));
limit--;
}
System.out.println(i);
if (i < list.size())
result.setHasMore();
}
} catch (Exception ex) {
throw new CustomRegistryException(ex.getMessage(), ex);
} finally {
}
result.setList(usrsForGroup);
return result;
}
return result;
}
/*
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#createCredential(java.lang.String)
*/
public WSCredential createCredential(String userSecurityName)
throws NotImplementedException, EntryNotFoundException,
CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
// This method is not called.
return null;
}
* (非 Javadoc)
*
* @see com.ibm.websphere.security.UserRegistry#createCredential(java.lang.String)
*/
public WSCredential createCredential(String userSecurityName)
throws NotImplementedException, EntryNotFoundException,
CustomRegistryException, RemoteException {
// TODO 自动生成方法存根
// This method is not called.
return null;
}
private boolean match(String name, String pattern) {
myRegExpSample regexp = new myRegExpSample(pattern);
boolean matches = false;
if (regexp.match(name))
matches = true;
return matches;
}
}
myRegExpSample regexp = new myRegExpSample(pattern);
boolean matches = false;
if (regexp.match(name))
matches = true;
return matches;
}
}
class myRegExpSample {
private boolean match(String s, int i, int j, int k) {
for (; k < expr.length; k++)
label0: {
Object obj = expr[k];
if (obj == STAR) {
if (++k >= expr.length)
return true;
if (expr[k] instanceof String) {
String s1 = (String) expr[k++];
int l = s1.length();
for (; (i = s.indexOf(s1, i)) >= 0; i++)
if (match(s, i + l, j, k))
return true;
for (; k < expr.length; k++)
label0: {
Object obj = expr[k];
if (obj == STAR) {
if (++k >= expr.length)
return true;
if (expr[k] instanceof String) {
String s1 = (String) expr[k++];
int l = s1.length();
for (; (i = s.indexOf(s1, i)) >= 0; i++)
if (match(s, i + l, j, k))
return true;
return false;
}
for (; i < j; i++)
if (match(s, i, j, k))
return true;
}
for (; i < j; i++)
if (match(s, i, j, k))
return true;
return false;
}
if (obj == ANY) {
if (++i > j)
return false;
break label0;
}
if (obj instanceof char[][]) {
if (i >= j)
return false;
char c = s.charAt(i++);
char ac[][] = (char[][]) obj;
if (ac[0] == NOT) {
for (int j1 = 1; j1 < ac.length; j1++)
if (ac[j1][0] <= c && c <= ac[j1][1])
return false;
}
if (obj == ANY) {
if (++i > j)
return false;
break label0;
}
if (obj instanceof char[][]) {
if (i >= j)
return false;
char c = s.charAt(i++);
char ac[][] = (char[][]) obj;
if (ac[0] == NOT) {
for (int j1 = 1; j1 < ac.length; j1++)
if (ac[j1][0] <= c && c <= ac[j1][1])
return false;
break label0;
}
for (int k1 = 0; k1 < ac.length; k1++)
if (ac[k1][0] <= c && c <= ac[k1][1])
break label0;
}
for (int k1 = 0; k1 < ac.length; k1++)
if (ac[k1][0] <= c && c <= ac[k1][1])
break label0;
return false;
}
if (obj instanceof String) {
String s2 = (String) obj;
int i1 = s2.length();
if (!s.regionMatches(i, s2, 0, i1))
return false;
i += i1;
}
}
}
if (obj instanceof String) {
String s2 = (String) obj;
int i1 = s2.length();
if (!s.regionMatches(i, s2, 0, i1))
return false;
i += i1;
}
}
return i == j;
}
}
public boolean match(String s) {
return match(s, 0, s.length(), 0);
}
return match(s, 0, s.length(), 0);
}
public boolean match(String s, int i, int j) {
return match(s, i, j, 0);
}
return match(s, i, j, 0);
}
public myRegExpSample(String s) {
Vector vector = new Vector();
int i = s.length();
StringBuffer stringbuffer = null;
Object obj = null;
for (int j = 0; j < i; j++) {
char c = s.charAt(j);
switch (c) {
case 63: /* '?' */
obj = ANY;
break;
Vector vector = new Vector();
int i = s.length();
StringBuffer stringbuffer = null;
Object obj = null;
for (int j = 0; j < i; j++) {
char c = s.charAt(j);
switch (c) {
case 63: /* '?' */
obj = ANY;
break;
case 42: /* '*' */
obj = STAR;
break;
obj = STAR;
break;
case 91: /* '[' */
int k = ++j;
Vector vector1 = new Vector();
for (; j < i; j++) {
c = s.charAt(j);
if (j == k && c == '^') {
vector1.addElement(NOT);
continue;
}
if (c == '\\') {
if (j + 1 < i)
c = s.charAt(++j);
} else if (c == ']')
break;
char c1 = c;
if (j + 2 < i && s.charAt(j + 1) == '-')
c1 = s.charAt(j += 2);
char ac1[] = { c, c1 };
vector1.addElement(ac1);
}
int k = ++j;
Vector vector1 = new Vector();
for (; j < i; j++) {
c = s.charAt(j);
if (j == k && c == '^') {
vector1.addElement(NOT);
continue;
}
if (c == '\\') {
if (j + 1 < i)
c = s.charAt(++j);
} else if (c == ']')
break;
char c1 = c;
if (j + 2 < i && s.charAt(j + 1) == '-')
c1 = s.charAt(j += 2);
char ac1[] = { c, c1 };
vector1.addElement(ac1);
}
char ac[][] = new char[vector1.size()][];
vector1.copyInto(ac);
obj = ac;
break;
vector1.copyInto(ac);
obj = ac;
break;
case 92: /* '\\' */
if (j + 1 < i)
c = s.charAt(++j);
break;
if (j + 1 < i)
c = s.charAt(++j);
break;
}
if (obj != null) {
if (stringbuffer != null) {
vector.addElement(stringbuffer.toString());
stringbuffer = null;
}
vector.addElement(obj);
obj = null;
} else {
if (stringbuffer == null)
stringbuffer = new StringBuffer();
stringbuffer.append(c);
}
}
if (obj != null) {
if (stringbuffer != null) {
vector.addElement(stringbuffer.toString());
stringbuffer = null;
}
vector.addElement(obj);
obj = null;
} else {
if (stringbuffer == null)
stringbuffer = new StringBuffer();
stringbuffer.append(c);
}
}
if (stringbuffer != null)
vector.addElement(stringbuffer.toString());
expr = new Object[vector.size()];
vector.copyInto(expr);
}
vector.addElement(stringbuffer.toString());
expr = new Object[vector.size()];
vector.copyInto(expr);
}
static final char NOT[] = new char[2];
static final Integer ANY = new Integer(0);
static final Integer STAR = new Integer(1);
Object expr[];
}
import java.sql.*;
import java.util.*;
==================================================
import java.sql.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import javax.sql.DataSource;
/*
* 创建日期 2006-7-12
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
* 创建日期 2006-7-12
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author 灵石
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class DbOperate {
public static Connection openConnection() throws Exception {
Connection conn = null;
try {
Context initContext = new InitialContext();
// Context envContext = (Context)
// initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) initContext
.lookup("jdbc/OraBzxxLoginM");
conn = ds.getConnection();
} catch (SQLException e1) {
e1.printStackTrace();
} catch (NameNotFoundException e0) {
e0.printStackTrace();
}
return conn;
}
* @author 灵石
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class DbOperate {
public static Connection openConnection() throws Exception {
Connection conn = null;
try {
Context initContext = new InitialContext();
// Context envContext = (Context)
// initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) initContext
.lookup("jdbc/OraBzxxLoginM");
conn = ds.getConnection();
} catch (SQLException e1) {
e1.printStackTrace();
} catch (NameNotFoundException e0) {
e0.printStackTrace();
}
return conn;
}
public static Connection openConnection(String driver, String url,
String username, String password) throws Exception {
Class.forName(driver).newInstance();
return DriverManager.getConnection(url, username, password);
}
String username, String password) throws Exception {
Class.forName(driver).newInstance();
return DriverManager.getConnection(url, username, password);
}
public static void closeConnection(Connection conn) throws Exception {
if (conn != null) {
conn.close();
}
}
if (conn != null) {
conn.close();
}
}
public static int getsqlcount(String sql) throws Exception {
Connection conn = openConnection("oracle.jdbc.OracleDriver",
"jdbc:oracle:thin:@192.168.0.127:1521:icbcfe", "loginm",
"123456");
int count = 0;
try {
Statement stmt = conn.createStatement();
ResultSet rs = null;
rs = stmt.executeQuery(sql);
while (rs.next()) {
count++;
}
} finally {
closeConnection(conn);
}
Connection conn = openConnection("oracle.jdbc.OracleDriver",
"jdbc:oracle:thin:@192.168.0.127:1521:icbcfe", "loginm",
"123456");
int count = 0;
try {
Statement stmt = conn.createStatement();
ResultSet rs = null;
rs = stmt.executeQuery(sql);
while (rs.next()) {
count++;
}
} finally {
closeConnection(conn);
}
return count;
}
}
public static List executeQuery(String sql) throws Exception {
Connection conn = openConnection("oracle.jdbc.OracleDriver",
"jdbc:oracle:thin:@192.168.0.127:1521:icbcfe", "loginm",
"123456");
Statement stmt = conn.createStatement();
ResultSet rs = null;
List list = new ArrayList();
try {
rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
Map map = new HashMap();
// String temp = null;
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
map.put(rsmd.getColumnName(i), rs.getObject(i));
// temp = rsmd.getColumnName(i);
}
// System.out.println(map.get(temp));
list.add(map);
Connection conn = openConnection("oracle.jdbc.OracleDriver",
"jdbc:oracle:thin:@192.168.0.127:1521:icbcfe", "loginm",
"123456");
Statement stmt = conn.createStatement();
ResultSet rs = null;
List list = new ArrayList();
try {
rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
Map map = new HashMap();
// String temp = null;
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
map.put(rsmd.getColumnName(i), rs.getObject(i));
// temp = rsmd.getColumnName(i);
}
// System.out.println(map.get(temp));
list.add(map);
}
} catch (SQLException e1) {
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null)
rs.close();
// if ( conn != null ) conn.close();
closeConnection(conn);
}
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null)
rs.close();
// if ( conn != null ) conn.close();
closeConnection(conn);
}
return list;
}
}
}
}

