473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to to arraylist in to database

hi!

I want to add arraylist of elements into database.
when i am running this it is giving error

public class Appraisal {


ArrayList<String> al=new ArrayList<String>();

private String m_str_employeeId;
private String m_date_promotionDate;
private String m_str_designation;
private String m_str_promoterId;
private String m_str_comments;


// Getting and Setting the Appraisal Bean



public String getM_date_promotionDate() {
return m_date_promotionDate;
}

public void setM_date_promotionDate(String date) {
m_date_promotionDate = date;
al.add(date);
}

public String getM_str_comments() {
return m_str_comments;
}

public void setM_str_comments(String m_str_comments) {
this.m_str_comments = m_str_comments;
al.add(m_str_comments);
}

public String getM_str_designation() {
return m_str_designation;
}

public void setM_str_designation(String m_str_designation) {
this.m_str_designation = m_str_designation;
al.add(m_str_designation);
}

public String getM_str_employeeId() {
return m_str_employeeId;
}

public void setM_str_employeeId(String id) {
m_str_employeeId = id;
al.add(id);
}

public String getM_str_promoterId() {
return m_str_promoterId;
}

public void setM_str_promoterId(String pid) {
m_str_promoterId = pid;
al.add(pid);
}


// returing list of designation available in employee_master_details
public ArrayList<String> getDesigation(){
ArrayList<String> al=new ArrayList<String>();
try {
//establishing the connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:HRIS"," hris","hydus");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("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.getString("designation"));
}
rs.close();
st.close();
con.close();
} catch (Exception e) {

e.printStackTrace();
}
return al;

}


// returing list of promoter ids available in designation_hierarchy_master and employee_master_detaisl

public ArrayList<String> getPromotersId(){
//storing list of promoters ids
ArrayList<String> al1=new ArrayList<String>();
try{
// establishing connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:HRIS"," hris","hydus");
Statement st=con.createStatement();
// Getting the employee_id from employee_master_details using designation_hierarchy_master
ResultSet rs=st.executeQuery("select employee_id from employee_master_details where designation in (select designation from designation_hierarchy_master where hierarchy_level=1)");

while(rs.next())
{
al1.add(rs.getString("employee_id"));
}
rs.close(); //closing result set object
st.close(); //statement object
con.close(); //connection object

}
catch(Exception e){
e.printStackTrace();
}
return al1;
}

public void saveAppraisal(){
//ArrayList<String> al2=new ArrayList<String>();

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:HRIS"," hris","hydus");
PreparedStatement pst=con.prepareStatement("insert into employee_promotion_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.executeUpdate();
if(y>0)
System.out.println("Promotion Updated");

pst.close();
con.commit();
con.close();

}
catch(Exception e){
e.printStackTrace();
}

}


}
Dec 17 '07 #1
1 10460
BigDaddyLH
1,216 Expert 1GB
I want to add arraylist of elements into database.
when i am running this it is giving error
When posting about an error you are causing, always be sure to include the error message itself, and indicate which line causes this error.
Dec 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Alex Ting | last post by:
Hi Everybody, I have an issue about deleting an object from an arrayList. I've bounded a datagrid using this code where it will first run through all of the code in loadQuestions() and bind a...
8
by: Patrick.O.Ige | last post by:
Hi All, I have a code below:- That Binds a DropDownList to a database using ArrayList. This code works well in ASP.NET webMatrix. But when i use it below in VS.NEt it gives me the error:-...
9
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
0
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
4
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type...
4
by: StinkyDuck | last post by:
I'm trying to determine which type of collection to use, DataTable or ArrayList. I understand that an ArrayList can be linked to databound objects if it contains the IList interface. Is there a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.