Hi Divya Shastry. Below is the code:
//this method I modify from your method
public Vector myMethod() {
Vector myVector=null;
try{
this.dbConnection();
String sql="select name,email from personal order by name";
PreparedStatement prepareStmt=con.prepareStatement(sql);
ResultSet rs=prepareStmt.executeQuery();
while(rs.next()){
myVector=new Vector();
myVector.addElement(rs.getString(1));// 1st data
myVector.addElement(rs.getString(2));// 2nd data
}
rs.close();
prepareStmt.close();
}catch(Exception ex){
System.out.println(ex.getMessage());
}finally{
return myVector;
}
}
//this at main
public static void main(String[] args){
CayukPah pah=new CayukPah();
pah.dbConnection();
Vector p_vektor=new Vector();
//-------1)try:Ulf Dittmer ---------
System.out.println("TRY GET DATA (1):1\n");
p_vektor=pah.getPersonData();
for(int i=0;i<p_vektor.size();i++){
Vector vec = (Vector) p_vektor.elementAt(i);
System.out.println("Nama: "+vec.elementAt(0));
System.out.println("Email: "+vec.elementAt(1));
System.out.println("\n");
}
p_vektor.clear(); //clear the elements
//-------2)try
ivya Shastry ---------
System.out.println("TRY GET DATA (2):1\n");
p_vektor=pah.myMethod();
for(int k=0;k<p_vektor.size();k++){
System.out.println("Nama: "+p_vektor.elementAt(k));
System.out.println("Email: "+p_vektor.elementAt(++k));
System.out.println("\n");
}
}
Regards,=)
-paoh-