This is my problem...

G

gbattine

Hi guys,
i need your help because i'm not able to solve my problem.
I read the BalusC article,well known in internet about datatable.
It speaks about using datatable as retrieving data from db.
I have to insert data into db table.
I've created a wrapper class that stores data from input fields and
i've created a datatable with input forms.
When i insert values in each row and click submit botton my table is
updated with null values. I think my error can be in this class,in
which i generate a datatable with rows number equals to user's choice
in a precedent page.
Here is my class

package giu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.sql.DataSource;

public class BiosamplesTable {
private List biosamples;//myTable è diventato User

private HtmlDataTable biosampleDataTable;

private Biosample biosampleItem;

private int nrows;


public HtmlDataTable getBiosampleDataTable(){
return biosampleDataTable;
}
public void setBiosampleDataTable(HtmlDataTable biosampleDataTable){
this.biosampleDataTable=biosampleDataTable;
}
public Biosample getBiosampleItem(){
return biosampleItem;
}
public void setBiosampleItem(Biosample biosampleItem){
this.biosampleItem=biosampleItem;
}
public List getBiosamples() throws Exception {
loadBiosamples(); // Reload after every request.
return biosamples;
}

// Setters ----------------------------------------------------------
/**
* @param users The users to set.
* @uml.property name="users"
*/
public void setBiosamples(List biosamples) {
this.biosamples = biosamples;
}

public void loadBiosamples() throws Exception {

List biosamples = new ArrayList();
for(int i=0;i<nrows;i++){
Biosample biosample=new Biosample();
biosamples.add(biosample);
}
setBiosamples(biosamples);


}
public int getNrows() {
return nrows;
}
public void setNrows(int nrows) {
this.nrows = nrows;
}
public void editBiosample(ActionEvent event) throws SQLException {


setBiosampleItem((Biosample) getBiosampleDataTable().getRowData());

if ((Biosample) getBiosampleDataTable().getRowData()!=null){
FacesContext facesContext=FacesContext.getCurrentInstance();
facesContext.addMessage(null,new
FacesMessage(FacesMessage.SEVERITY_ERROR,"Il rowdata è pieno.","Row
data pieno."));

}else
{FacesContext facesContext=FacesContext.getCurrentInstance();
facesContext.addMessage(null,new
FacesMessage(FacesMessage.SEVERITY_ERROR,"Il rowdata è vuoto.","Row
data vuoto."));
}
DataSource dataSource = Singleton.getInstance().getDataSource();


Connection conn = dataSource.getConnection();


if (conn != null) {


PreparedStatement pst3 = null;
pst3 = conn .prepareStatement("INSERT INTO
campione(id_,organismo,protocollotrattamento,metodoestrazione,tipoamplificazione,protocolloibridazione,protocollomarcatura,valore1,valore2,valore3,valore4)
VALUES(?,?,?,?,?,?,?,?,?,?,?)");

pst3.setInt(1, 20);
pst3.setString(2, biosampleItem.getOrganism());
pst3.setString(3, biosampleItem.getTreatmentProtocol());
pst3.setString(4, biosampleItem.getExtractionMethod());
pst3.setString(5, biosampleItem.getAmplification());
pst3.setString(6, biosampleItem.getHybridation());
pst3.setString(7, biosampleItem.getLabel());
pst3.setString(8, biosampleItem.getExpFact1());
pst3.setString(9, biosampleItem.getExpFact2());
pst3.setString(10, biosampleItem.getExpFact3());
pst3.setString(11, biosampleItem.getExpFact4());
pst3.executeUpdate();
pst3.close();
conn.close();
}
}
}


whit this operations

List biosamples = new ArrayList();
for(int i=0;i<nrows;i++){
Biosample biosample=new Biosample();
biosamples.add(biosample);
}
setBiosamples(biosamples);


i create a datatable with N rows,if N is user's choice.
Is there an error in my procedure?
If no
it is my jsp page,with a command link for each row and a submit button
for navigation...
WHAT'S WRONG?
Why my table is updated with only NULL values(the default for my
table?).

The first columns of my table is right,that is updated with value 20
pst3.setInt(1, 20);

,the others are null.Please help me....i'm crazying..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top