Ediiting a datatable
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ch_mourya
Posted On:   Friday, February 22, 2008 12:15 PM

i connecting to a database, retrieving and displaying the data using jsf datatable, now i want to select individual row and edit it, so that it will be reflected in the database my bean package backend; import java.util.ArrayList; import java.util.List; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import java.sql.SQLException; import javax.faces.context.FacesContext; import java.util.Vector; public class MyBean { private Connection conn; private MyData[] emlist; public MyData[] getEmlist() { return    More>>

i connecting to a database, retrieving and displaying the data using jsf datatable, now i want to select individual row and edit it, so that it will be reflected in the database

my bean

package backend;

import java.util.ArrayList;
import java.util.List;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.faces.context.FacesContext;
import java.util.Vector;


public class MyBean {

private Connection conn;
private MyData[] emlist;

public MyData[] getEmlist() {
return emlist;
}

public void setEmlist(MyData[] emlist) {
this.emlist = emlist;
}


public MyBean(){

String driver = "org.apache.derby.jdbc.ClientDriver";
String connectionURL = "jdbc:derby://localhost:1527/cart;";

try{
Class.forName(driver).newInstance();
System.out.println(driver + " loaded. ");
}
catch(java.lang.ClassNotFoundException e) {
e.printStackTrace();
}

catch (Exception E)
{
System.out.println("Unable to load driver.");
E.printStackTrace();
}
try {
conn = DriverManager.getConnection(connectionURL);
System.out.println("Connected to database ");
try{
Statement s = conn.createStatement();
ResultSet rs=s.executeQuery("select * from cart");
Vector temp=new Vector ();
while(rs.next()){

MyData myDataItem = new MyData();
myDataItem.setName(rs.getString(1));
myDataItem.setCat(rs.getString(2));
myDataItem.setDesc(rs.getString(3));
myDataItem.setPrice(rs.getDouble(4));
myDataItem.setSales(rs.getDouble(5));
myDataItem.setPicture(rs.getString(6));
temp.add(myDataItem);
//myDataItem.setEnabled(rs.getInt(i));

}
emlist=new MyData[temp.size()];
int i=0;
for(MyData myDataItem: temp){
emlist[i++]=myDataItem;
}
}catch(Exception ex){
ex.printStackTrace();
}
}
catch (SQLException e) {
e.printStackTrace();
}

}


}

   <<Less
About | Sitemap | Contact