안드로이드-jsp-oracle 연동해서 안드로이드에서 내용을 입력하면 오라클 db에 저장되는것을 구현했습니다.
하지만 어플내에서 롱크릭리스너를 이용해서 꾹 누르면 삭제는 되는데 문제는 오라클db테이블 내용은 삭제가 되지 않습니다.
어떡하면 리스트뷰 삭제와 동시에 db 테이블 내용도 삭제를 할 수 있는지 도움을 요청 하고자 합니다 도와주세요 ㅠㅠ
import java.io.*;
import java.util.*;
import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.*;
import org.apache.http.impl.client.*;
import org.apache.http.message.*;
import org.xmlpull.v1.*;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.*;
import android.os.Bundle;
import android.util.*;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.OnItemLongClickListener;
public class MainActivity extends Activity {
Button btn;
ListView lv;
ArrayList<EmpDTO> list;
CustomAdapter adapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView)findViewById(R.id.listView1);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), InsertActivity.class );
startActivity(intent);
}
});
}
public InputStream requestGet(String requestURL) {
Log.i("xxx", "requestGet start");
try {
HttpClient client = new DefaultHttpClient();
List<NameValuePair> List = new ArrayList<NameValuePair>();
HttpGet get = new HttpGet(requestURL);
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
return is ;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public String streamToString(InputStream is) {
StringBuffer buffer = new StringBuffer();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
String str = reader.readLine();
while(str != null) {
buffer.append(str+"\n");
str = reader.readLine();
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
return buffer.toString();
}
public ArrayList<EmpDTO> getXML(InputStream is) {
ArrayList<EmpDTO> list = new ArrayList<EmpDTO>();
Log.i("xxx", "getXML start!");
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(is,"utf-8");
int eventType = parser.getEventType();
EmpDTO dto = null;
while( eventType != XmlPullParser.END_DOCUMENT) {
switch(eventType) {
case XmlPullParser.START_TAG:
String startTag = parser.getName();
if(startTag.equals("record")){ dto=new EmpDTO();}
if(dto !=null){
if(startTag.equals("loc")){ dto.setLoc(parser.nextText()); }
} else { Log.i("xxx", "dto = null"); }
break;
case XmlPullParser.END_TAG:
String endTag = parser.getName();
if(endTag.equals("record")){
list.add(dto);
}
}
eventType = parser.next();
}
for( EmpDTO xx : list){
Log.i("xxx",""+xx.getLoc());
}
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException ie) {
// TODO Auto-generated catch block
ie.printStackTrace();
}
return list;
}
@Override
protected void onResume() {
super.onResume();
String requestURL = "http://192.168.123.189:8181/Orginal/s2a11.jsp";
InputStream is = requestGet(requestURL);
final ArrayList<EmpDTO> list = getXML(is);
adapter = new CustomAdapter(getApplicationContext(),list,R.layout.custom_list);
lv.setAdapter(adapter);
/* 리스트뷰 롱클릭시 삭제 다이얼로그 */
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
final int position, long id) {
AlertDialog diaBox=new AlertDialog.Builder(MainActivity.this)
.setTitle("삭제")
.setMessage("해당 조를 삭제하시겠습니까?")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
list.remove(position);
lv.clearChoices();
adapter.notifyDataSetChanged();
}
})
.setNegativeButton("NO", null)
.create();
diaBox.show();
return false;
}
});
}}