标题:[求助] jsf 实现的关于删除用户信息的代码,谁给我看下吧 ,不能够删除数据 ...
取消只看楼主
renlong1333
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-5-6
 问题点数:0 回复次数:1 
[求助] jsf 实现的关于删除用户信息的代码,谁给我看下吧 ,不能够删除数据库里的内

一个连接数据库的JAVABEAN:
package com.jsfdemo.beans;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.sql.*;
import javax.sql.DataSource;
public class DBConnection {
Connection con ;

public Connection dataSource() {
try{
Context ctx = new InitialContext();
if(ctx==null)throw new NamingException ("no initial context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/dbtest");
if(ds==null) throw new NamingException ("no dataSource ");
con = ds.getConnection();
}catch (NamingException e){

}catch (SQLException e){

}
return con;
}
}
一个课题SUBJECT的BEAN:
package com.jsfdemo.beans;

public class SubjectBean {
private String sb_id;
private String sb_name;
private String sb_desc;
private String t_name;
private String sb_state;
//--------------------------
public SubjectBean(){

}
//--------------------------
public String getSb_desc() {
return sb_desc;
}
public void setSb_desc(String sb_desc) {
this.sb_desc = sb_desc;
}
public String getSb_id() {
return sb_id;
}
public void setSb_id(String sb_id) {
this.sb_id = sb_id;
}
public String getSb_name() {
return sb_name;
}
public void setSb_name(String sb_name) {
this.sb_name = sb_name;
}
public String getSb_state() {
return sb_state;
}
public void setSb_state(String sb_state) {
this.sb_state = sb_state;
}
public String getT_name() {
return t_name;
}
public void setT_name(String t_name) {
this.t_name = t_name;
}
public SubjectBean(String sb_id,String sb_name,String sb_desc,String t_name,String sb_state ){
this.sb_id = sb_id;
this.sb_name = sb_name;
this.sb_desc = sb_desc;
this.t_name = t_name;
this.sb_state = sb_state;

}
}

一个操作数据库的Bean(删除功能):
package com.jsfdemo.beans;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Vector;
//import javax.servlet.jsp.jstl.sql.ResultSupport;
//import javax.servlet.jsp.jstl.sql.Result;
import java.sql.SQLException;
import java.sql.*;

public class SbDB {
DBConnection DBConnection = new DBConnection();
public void deleteSubject(String sbName)throws Exception{

try{
Connection con = DBConnection.dataSource();
Statement st = con.createStatement();
String deleteSql = "delete from subjectInfo where sb_id = "+sbName+"";
st.executeUpdate(deleteSql);
// pst =con.prepareStatement("delete from subjectInfo where sb_name=? ");
//pst.setString(1, sbName);
//pst.executeQuery();
con.close();
}catch(Exception e){
e.printStackTrace();

}


}
一个用与JSP和BEAN交互的类(删除功能):
package com.jsfdemo.beans;
import java.util.List;
public class SbManager {

private SubjectBean subjectB = new SubjectBean();
private SbDB sbdb = new SbDB();
//*************************************

public SbManager(){

}
public SubjectBean getSubjectB() {
return subjectB;
}
public void setSubjectB(SubjectBean subjectB) {
this.subjectB = subjectB;
}
public SbDB getSbdb() {
return sbdb;
}

public void setSbdb(SbDB sbdb) {
this.sbdb = sbdb;
}
public String delete(){
try{
sbdb.deleteSubject(subjectB.getSb_name());
}catch(Exception e){
e.printStackTrace();
}
return "deleteOK";
}
JSP页面:
<%@ page language = "java" contentType = "text/html;charset = gb2312"%>
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<html>
<f:view>
<f:loadBundle basename = "com.jsfdemo.messages" var = "msgs"/>
<center>
<h:form>
<head>
<title>
delete subject form
</title>
</head>
<body>

<h:outputText value = "#{msgs.deleteSubject}"></h:outputText>
<h:outputText value = "#{msgs.subjectID}"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_name}"></h:inputText>
<h:commandButton value = "delete...." action = "#{SbManager.delete}"></h:commandButton>
<h:outputText value = "#{SbManager.subjectB.sb_name}"></h:outputText>

</body>
</h:form>
</center>
</f:view>
</html>

不能够实现删除共能,点击删除键没有任何反映,哪个高手帮我看看吧。谢谢了
我是做毕业设计,是个新手,如果谁有类似的代码可以给我发来看下吗?
谢谢啊。我的毕业设计是毕业生选题系统。有谁可以给我分享下??

[此贴子已经被作者于2007-5-7 14:56:19编辑过]

搜索更多相关主题的帖子: jsf 数据库 import javax DataSource 
2007-05-07 14:53
renlong1333
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-5-6
得分:0 

我改了下(是因为给传了错误的值),但是还是出现了这样的错误:请问这一般是什么错误???

javax.servlet.ServletException: Error testing property 'sb_name' in bean of type null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)


root cause

javax.faces.el.PropertyNotFoundException: Error testing property 'sb_name' in bean of type null
com.sun.faces.el.PropertyResolverImpl.getType(PropertyResolverImpl.java:342)
com.sun.faces.el.impl.ArraySuffix.getType(ArraySuffix.java:240)
com.sun.faces.el.impl.ComplexValue.getType(ComplexValue.java:208)
com.sun.faces.el.ValueBindingImpl.getType(ValueBindingImpl.java:338)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:111)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:702)
javax.faces.component.UIInput.validate(UIInput.java:627)
javax.faces.component.UIInput.executeValidate(UIInput.java:838)
javax.faces.component.UIInput.processValidators(UIInput.java:412)
javax.faces.component.UIForm.processValidators(UIForm.java:170)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:904)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:342)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:78)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

2007-05-07 16:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-137425-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.439000 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved