标题:[求助] JavaBean的问题
只看楼主
chenpin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-4-26
 问题点数:0 回复次数:9 
[求助] JavaBean的问题
我现在遇到一个问题就是在JAVA与数据库的连接的时候,为什么我对单一的一个表进行修改,添加.....这些操作的时候不行呢??  就是用executUpdate来执行的嘛   但是总要出错,错误的信息是java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
at sun.jdbc.odbc.JdbcOdbcResultSet.beforeFirst(JdbcOdbcResultSet.java:2121)
at JavaBean.JBTest.actionPerformed(JBTest.java:47)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
请大家帮一下忙  
搜索更多相关主题的帖子: JavaBean 
2007-04-26 18:36
黄袖标
Rank: 4
等 级:贵宾
威 望:13
帖 子:676
专家分:0
注 册:2007-3-22
得分:0 

数据库用是是mssql吧?


我胡汉三又回来啦!物是人非啊,只有静夜思大大还在。
2007-04-26 18:40
黄袖标
Rank: 4
等 级:贵宾
威 望:13
帖 子:676
专家分:0
注 册:2007-3-22
得分:0 

如果是,可以换最新的jdbc驱动,1.0可能不支持,2.0以后支持了,然后就是不要设置结果集的游标滚动,其中有3个可选设置,只有Result set type is TYPE_FORWARD_ONLY这个不行,楼主换个设置看看吧.


我胡汉三又回来啦!物是人非啊,只有静夜思大大还在。
2007-04-26 18:46
chenpin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-4-26
得分:0 

是的  我用的数据库是ms_sql  但是我如果上面写了一些控件就行,比如说查询之类的

我还是才开始学的J2EE   希望大家多帮助一下   谢谢   

2007-04-26 18:53
黄袖标
Rank: 4
等 级:贵宾
威 望:13
帖 子:676
专家分:0
注 册:2007-3-22
得分:0 
我也很少使用mssql,但是听你描述上面写过就可以,可能是你上面做了设置,然后下面仍沿用这个设置,但是你去掉之后可能就用了另外的设置,我也是不确定的说,lz可以试下.

我胡汉三又回来啦!物是人非啊,只有静夜思大大还在。
2007-04-26 18:58
luke911
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2005-10-21
得分:0 
(JBTest.java:47)
这里出错啦,去看看怎么导致的就行了
2007-04-29 16:56
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2959
专家分:652
注 册:2007-1-19
得分:0 
java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY
也许是指针的移动方式不对吧!

我的网站 http://www.
2007-04-29 17:18
farain
Rank: 1
等 级:新手上路
威 望:1
帖 子:80
专家分:0
注 册:2006-2-23
得分:0 
你到是把你代码贴出来看看啊

2007-04-30 10:52
renlong1333
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-5-6
得分:0 

一个关于课题Subject的JAVABean:
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;

}
}


一个数据库连接池的类:
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 {

static 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 ");
// Connection con = ds.getConnection();
}catch (NamingException e){

//}catch (SQLException e){

}
return null;
}
}

一个操作数据库的JAVABean:
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;

public class SbDB {
// private Result AllSubject;
//********************************************
public void addSubject(SubjectBean subject) throws Exception,SQLException{
try{
Connection con =DBConnection.dataSource();
PreparedStatement pst = null;
//try{
pst = con.prepareStatement("insert into subjectInfo(sb_id,sb_name,sb_desc,t_id,sb_state) values(?,?,?,?,?)");
pst.setString(1, subject.getSb_id());
pst.setString(2, subject.getSb_name());
pst.setString(3, subject.getSb_desc());
pst.setString(4, subject.getT_name());
pst.setString(5, subject.getSb_state());
pst.executeUpdate();
//}catch(Exception e){
// e.printStackTrace();
//}
con.close();

}catch(Exception e){
e.printStackTrace();
}

}
}
// ********************************************

一个和JSP界面及JAVABean交互的类:
package com.jsfdemo.beans;
import javax.faces.event.ActionEvent;
import javax.servlet.jsp.jstl.sql.Result;


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 add(){
try{
sbdb.addSubject(subjectB);
}catch(Exception e){
e.printStackTrace();
}
return "addOK";
}

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>
<center>
<f:view>
<h:form>

<head>
<title>
add the subject
</title>
</head>
<body>
<h:panelGrid columns = "2">
<h:outputText value = "subjectID"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_id}"></h:inputText>
<h:outputText value = "subjectName"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_name}"></h:inputText>
<h:outputText value = "subjectDesc"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_desc}"></h:inputText>
<h:outputText value = "teacher'sName"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.t_name}"></h:inputText>
<h:outputText value = "subject'sState"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_state}"></h:inputText>
<h:commandButton value = "submit..." action = "#{SbManager.add}"></h:commandButton>
</h:panelGrid>
<h:dataTable value = "#{SbManager.subjectB}" var = "sb" border = "1">
<h:column>
<f:facet name="header">
<h:outputText value = "subjectID"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_id}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subjectName"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subjectDesc"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_desc}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "teacher'sName"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.t_name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subject'sState"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_state}"></h:outputText>
</h:column>
</h:dataTable>

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

其他配置正确(因为我做了测试),我先是把这些代码全部写在一个类里,能实现其功能,但是那样感觉太乱了,所以我把这些代码给分别写在了类里,结果是:
提交后,不显示错误,也不往数据库里插入信息,我已经是到了“山穷水尽”的地步了,实在解决不了这个问题,希望高手帮帮忙,谢谢啊!!!

2007-05-06 15:53
支离破碎
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:737
专家分:0
注 册:2007-1-4
得分:0 
你的游标类型是向前只读型的,不能执行更新

人生漂泊無依,有如浮萍菱花,隨水飄流,你会在我这里停留吗?
[url=http://51mynet.]http://51mynet.[/url]
2007-05-07 08:39



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




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

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