Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从Vaadin表更新数据库_Java_Sql_Database_Vaadin - Fatal编程技术网

Java 从Vaadin表更新数据库

Java 从Vaadin表更新数据库,java,sql,database,vaadin,Java,Sql,Database,Vaadin,我有一个数据库表,其中已经存储了一些数据 现在,我希望在我的页面中有一个Vaadin可编辑表,其中包含从数据库获取的数据,当更新该Vaadin表时(添加行或编辑现有行),数据库也应该更新 我非常接近于此,但我意识到我不能只使用插入查询,因为违反了唯一ID约束 为了实现这一目标,我能做些什么?我真的需要你的帮助 BeanItemContainer: public BeanItemContainer createContainer() { Bea

我有一个数据库表,其中已经存储了一些数据

现在,我希望在我的页面中有一个Vaadin可编辑表,其中包含从数据库获取的数据,当更新该Vaadin表时(添加行或编辑现有行),数据库也应该更新

我非常接近于此,但我意识到我不能只使用插入查询,因为违反了唯一ID约束

为了实现这一目标,我能做些什么?我真的需要你的帮助

BeanItemContainer

public BeanItemContainer createContainer() {                
           BeanItemContainer<Sct> beans = new BeanItemContainer<Sct>(Sct.class);

           beans.addNestedContainerProperty("secti.sid");
           beans.addNestedContainerProperty("secti.isa");
           beans.addNestedContainerProperty("secti.order");

        for (int i = 0; i < list.size(); i++) {
            PS_SECTION section = list.get(i);

                Long ps =  section.getPS_SECTION();
                String na = section.getNAME();
                Long is = section.getISACTIVE();
                Long or = section.getVORDER();

             Object itemId = beans.addBean(new Sct(na, new BeanSect(ps, is, or)));
        }

        return beans;
    }
public BeanItemContainer createContainer(){
BeanItemContainer bean=新的BeanItemContainer(Sct.class);
beans.addNestedContainerProperty(“secti.sid”);
beans.addNestedContainerProperty(“secti.isa”);
beans.addNestedContainerProperty(“部门订单”);
对于(int i=0;i
单击时,这里是保存(更新)按钮:

        ClickListener saveListener = new ClickListener() {          
            private Long s4 = 0L;

            @Override
            public void buttonClick(ClickEvent event) {     

                    Collection<?> itemIds =  table.getItemIds();
                     Item item = null;
                     boolean isSaved = false;
                     PS_SECTION ps = null;
                     List<PS_SECTION> newlist = new ArrayList<PS_SECTION>();
                     int i = 0;

                     for(Object itemId : itemIds){   
                            ps = new PS_SECTION();
                            item = table.getItem(itemId);  

                            Long s1 = (Long) item.getItemProperty("ID").getValue();
                            String s2 = item.getItemProperty("SECTION").getValue().toString();
                            Long s3 = (Long) item.getItemProperty("ORDER").getValue();
                            Long s5 = 0L;

                            ps.setPS_SECTION(s1);
                            ps.setNAME(s2);
                            ps.setVORDER(s3);
                            ps.setISACTIVE(s4);
                            ps.setISGLOBAL(s5);                     
                            newlist.add(ps);
                         }

                            try {
// Here I call the query.                                                       
                              isSaved = dao.insertPsSections(newlist); 

                                if (isSaved){                       
                                    Notification.show("Success ");
                                    unsavedChanges = false;
                                }
                                else if (!isSaved){
                                    Notification.show("Problem");
                                }                        
                            } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }                           

            }
        };
public boolean insertPsSections(List<PS_SECTION> pssec)  throws SQLException {  
        Boolean sv = false;     
        try {                           
            this.setKeepConnOpen(true);             
            String insertsections = "INSERT INTO PS_SECTION"
                    + "(PS_SECTION,NAME,ISACTIVE,ISGLOBAL,VORDER)"
                    + "VALUES (?,?,?,?,?)";

            for (PS_SECTION j : pssec){                                         
                Long section = j.getPS_SECTION();
                String name = j.getNAME();
                Long isa = j.getISACTIVE();
                Long isg = j.getISGLOBAL();
                Long order = j.getVORDER();

                this.simpleUpdate(insertsections, false, section, name, isa, isg, order);
            }

        } finally {
            this.doCommit();
            this.closeConn(true);
            sv=true;
        }
        return sv;
    }
ClickListener saveListener=新建ClickListener(){
专用长s4=0L;
@凌驾
公共无效按钮单击(单击事件){
集合itemIds=table.getItemIds();
Item=null;
布尔值isSaved=false;
PS_段PS=null;
List newlist=newarraylist();
int i=0;
对于(对象itemId:itemIds){
ps=新ps_段();
item=table.getItem(itemId);
Long s1=(Long)item.getItemProperty(“ID”).getValue();
字符串s2=item.getItemProperty(“节”).getValue().toString();
Long s3=(Long)item.getItemProperty(“订单”).getValue();
长s5=0L;
ps.setPS_段(s1);
ps.setNAME(s2);
p.setVORDER(s3);
ps.setISACTIVE(s4);
ps.setISGLOBAL(s5);
新增(ps);
}
试一试{
//这里我称之为查询。
isSaved=dao.insertPsSections(newlist);
如果(已保存){
通知。显示(“成功”);
未保存的更改=错误;
}
否则,如果(!isSaved){
通知。显示(“问题”);
}                        
}捕获(SQLE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}                           
}
};
最后,查询:

        ClickListener saveListener = new ClickListener() {          
            private Long s4 = 0L;

            @Override
            public void buttonClick(ClickEvent event) {     

                    Collection<?> itemIds =  table.getItemIds();
                     Item item = null;
                     boolean isSaved = false;
                     PS_SECTION ps = null;
                     List<PS_SECTION> newlist = new ArrayList<PS_SECTION>();
                     int i = 0;

                     for(Object itemId : itemIds){   
                            ps = new PS_SECTION();
                            item = table.getItem(itemId);  

                            Long s1 = (Long) item.getItemProperty("ID").getValue();
                            String s2 = item.getItemProperty("SECTION").getValue().toString();
                            Long s3 = (Long) item.getItemProperty("ORDER").getValue();
                            Long s5 = 0L;

                            ps.setPS_SECTION(s1);
                            ps.setNAME(s2);
                            ps.setVORDER(s3);
                            ps.setISACTIVE(s4);
                            ps.setISGLOBAL(s5);                     
                            newlist.add(ps);
                         }

                            try {
// Here I call the query.                                                       
                              isSaved = dao.insertPsSections(newlist); 

                                if (isSaved){                       
                                    Notification.show("Success ");
                                    unsavedChanges = false;
                                }
                                else if (!isSaved){
                                    Notification.show("Problem");
                                }                        
                            } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }                           

            }
        };
public boolean insertPsSections(List<PS_SECTION> pssec)  throws SQLException {  
        Boolean sv = false;     
        try {                           
            this.setKeepConnOpen(true);             
            String insertsections = "INSERT INTO PS_SECTION"
                    + "(PS_SECTION,NAME,ISACTIVE,ISGLOBAL,VORDER)"
                    + "VALUES (?,?,?,?,?)";

            for (PS_SECTION j : pssec){                                         
                Long section = j.getPS_SECTION();
                String name = j.getNAME();
                Long isa = j.getISACTIVE();
                Long isg = j.getISGLOBAL();
                Long order = j.getVORDER();

                this.simpleUpdate(insertsections, false, section, name, isa, isg, order);
            }

        } finally {
            this.doCommit();
            this.closeConn(true);
            sv=true;
        }
        return sv;
    }
public boolean insertPsSections(List pssec)抛出SQLException{
布尔sv=假;
试试{
这个.setKeepConnOpen(true);
String insertsections=“插入PS\U节”
+(PS_部分、名称、ISACTIVE、ISGLOBAL、VORDER)
+“值(?,?,?,?)”;
对于(PS_第j节:pssec){
长截面=j.getPS_截面();
String name=j.getNAME();
Long isa=j.getISACTIVE();
Long isg=j.getISGLOBAL();
长阶=j.getVORDER();
simpleUpdate(insertsections,false,section,name,isa,isg,order);
}
}最后{
this.doCommit();
这是closeConn(真的);
sv=真;
}
返回sv;
}