hi!
I want to add arraylist of elements into database.
when i am running this it is giving error
public class Appraisal {
ArrayList<Strin g> al=new ArrayList<Strin g>();
private String m_str_employeeI d;
private String m_date_promotio nDate;
private String m_str_designati on;
private String m_str_promoterI d;
private String m_str_comments;
// Getting and Setting the Appraisal Bean
public String getM_date_promo tionDate() {
return m_date_promotio nDate;
}
public void setM_date_promo tionDate(String date) {
m_date_promotio nDate = date;
al.add(date);
}
public String getM_str_commen ts() {
return m_str_comments;
}
public void setM_str_commen ts(String m_str_comments) {
this.m_str_comm ents = m_str_comments;
al.add(m_str_co mments);
}
public String getM_str_design ation() {
return m_str_designati on;
}
public void setM_str_design ation(String m_str_designati on) {
this.m_str_desi gnation = m_str_designati on;
al.add(m_str_de signation);
}
public String getM_str_employ eeId() {
return m_str_employeeI d;
}
public void setM_str_employ eeId(String id) {
m_str_employeeI d = id;
al.add(id);
}
public String getM_str_promot erId() {
return m_str_promoterI d;
}
public void setM_str_promot erId(String pid) {
m_str_promoterI d = pid;
al.add(pid);
}
// returing list of designation available in employee_master _details
public ArrayList<Strin g> getDesigation() {
ArrayList<Strin g> al=new ArrayList<Strin g>();
try {
//establishing the connection
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
Statement st=con.createSt atement();
ResultSet rs=st.executeQu ery("select distinct designation from employee_master _details");
// adding list of all designations available from employee_master _details to arrayList
while(rs.next() )
{
al.add(rs.getSt ring("designati on"));
}
rs.close();
st.close();
con.close();
} catch (Exception e) {
e.printStackTra ce();
}
return al;
}
// returing list of promoter ids available in designation_hie rarchy_master and employee_master _detaisl
public ArrayList<Strin g> getPromotersId( ){
//storing list of promoters ids
ArrayList<Strin g> al1=new ArrayList<Strin g>();
try{
// establishing connection
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
Statement st=con.createSt atement();
// Getting the employee_id from employee_master _details using designation_hie rarchy_master
ResultSet rs=st.executeQu ery("select employee_id from employee_master _details where designation in (select designation from designation_hie rarchy_master where hierarchy_level =1)");
while(rs.next() )
{
al1.add(rs.getS tring("employee _id"));
}
rs.close(); //closing result set object
st.close(); //statement object
con.close(); //connection object
}
catch(Exception e){
e.printStackTra ce();
}
return al1;
}
public void saveAppraisal() {
//ArrayList<Strin g> al2=new ArrayList<Strin g>();
try{
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
PreparedStateme nt pst=con.prepare Statement("inse rt into employee_promot ion_details values(?,?,?,?, ?)");
pst.setString(1 ,al.get(0));
pst.setString(2 ,al.get(1) );
pst.setString(3 ,al.get(3));
pst.setString(4 ,al.get(4));
pst.setString(5 ,al.get(5));
int y=pst.executeUp date();
if(y>0)
System.out.prin tln("Promotion Updated");
pst.close();
con.commit();
con.close();
}
catch(Exception e){
e.printStackTra ce();
}
}
}
I want to add arraylist of elements into database.
when i am running this it is giving error
public class Appraisal {
ArrayList<Strin g> al=new ArrayList<Strin g>();
private String m_str_employeeI d;
private String m_date_promotio nDate;
private String m_str_designati on;
private String m_str_promoterI d;
private String m_str_comments;
// Getting and Setting the Appraisal Bean
public String getM_date_promo tionDate() {
return m_date_promotio nDate;
}
public void setM_date_promo tionDate(String date) {
m_date_promotio nDate = date;
al.add(date);
}
public String getM_str_commen ts() {
return m_str_comments;
}
public void setM_str_commen ts(String m_str_comments) {
this.m_str_comm ents = m_str_comments;
al.add(m_str_co mments);
}
public String getM_str_design ation() {
return m_str_designati on;
}
public void setM_str_design ation(String m_str_designati on) {
this.m_str_desi gnation = m_str_designati on;
al.add(m_str_de signation);
}
public String getM_str_employ eeId() {
return m_str_employeeI d;
}
public void setM_str_employ eeId(String id) {
m_str_employeeI d = id;
al.add(id);
}
public String getM_str_promot erId() {
return m_str_promoterI d;
}
public void setM_str_promot erId(String pid) {
m_str_promoterI d = pid;
al.add(pid);
}
// returing list of designation available in employee_master _details
public ArrayList<Strin g> getDesigation() {
ArrayList<Strin g> al=new ArrayList<Strin g>();
try {
//establishing the connection
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
Statement st=con.createSt atement();
ResultSet rs=st.executeQu ery("select distinct designation from employee_master _details");
// adding list of all designations available from employee_master _details to arrayList
while(rs.next() )
{
al.add(rs.getSt ring("designati on"));
}
rs.close();
st.close();
con.close();
} catch (Exception e) {
e.printStackTra ce();
}
return al;
}
// returing list of promoter ids available in designation_hie rarchy_master and employee_master _detaisl
public ArrayList<Strin g> getPromotersId( ){
//storing list of promoters ids
ArrayList<Strin g> al1=new ArrayList<Strin g>();
try{
// establishing connection
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
Statement st=con.createSt atement();
// Getting the employee_id from employee_master _details using designation_hie rarchy_master
ResultSet rs=st.executeQu ery("select employee_id from employee_master _details where designation in (select designation from designation_hie rarchy_master where hierarchy_level =1)");
while(rs.next() )
{
al1.add(rs.getS tring("employee _id"));
}
rs.close(); //closing result set object
st.close(); //statement object
con.close(); //connection object
}
catch(Exception e){
e.printStackTra ce();
}
return al1;
}
public void saveAppraisal() {
//ArrayList<Strin g> al2=new ArrayList<Strin g>();
try{
Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
Connection con=DriverManag er.getConnectio n("jdbc:odbc:HR IS","hris","hyd us");
PreparedStateme nt pst=con.prepare Statement("inse rt into employee_promot ion_details values(?,?,?,?, ?)");
pst.setString(1 ,al.get(0));
pst.setString(2 ,al.get(1) );
pst.setString(3 ,al.get(3));
pst.setString(4 ,al.get(4));
pst.setString(5 ,al.get(5));
int y=pst.executeUp date();
if(y>0)
System.out.prin tln("Promotion Updated");
pst.close();
con.commit();
con.close();
}
catch(Exception e){
e.printStackTra ce();
}
}
}
Comment