I have a table:’Categories’ which has two fields:Category_ID and Category. Data in Category_ID field are like ‘c1′,’c2’. If There are 10 rows then from c1 to c10. When I insert new record in this table,how can I set the Category_ID like c11 or c12? If none of the record is deleted then its easy to set it according to number of rows.But User can delete the records. I have tried to retrieve Category_ID from the table, stored it in vector, then set one string variable which stores all category_ids separated by ‘;’ I thought to separate c and related digit from Category_ID so that can use the next digit in insert query.
Statement st;
ResultSet rsCatID;
String query="";
String querySelect="";//used to get last category_id number,so that next value will be applied in insert query.
Vector vCatID=new Vector();
String strCatID="";
String[] arrCatID;
Then in try catch block-lines after connection,
querySelect="select Category_ID from Categories";
rsCatID=st.executeQuery(querySelect);
while(rsCatID.next()){
vCatID.add(rsCatID.getString("Category_ID").toString());
}
for(int i=0;i<vCatID.size();i++){
strCatID+=vCatID.get(i).toString()+";";
}
System.out.println("strcatidcount=="+strCatID);
arrCatID=strCatID.split(";");
for(int i=0;i<arrCatID.length;i++){
System.out.println("arrCatID=="+arrCatID[i]);
}
Now want to split digit from array and want to insert next value and attached it with the character ‘c’ and insert the whole new record. How can I split it? eg. if category_id is c3 then 3 must be stored in another array and for new record 4 ,(c4) will be inserted.
ALTERNATIVELY:
This will bring the highest intnum back