public void insert(){ final String fname=name.getText().toString(); final String fcity=city.getText().toString(); ResultSet rs; try{ Statement statement1=connect.createStatement(); rs=statement1.executeQuery("SELECT * FROM FORM1"); List<Map<string,string>>data1=null; data1=new ArrayList<Map<string,string>>(); while(rs.next()){ Map<string,string>datanum1=new HashMap<string,string>(); datanum1.put("a", rs.getString("NAME")); datanum1.put("b", rs.getString("CITY")); data1.add(datanum1); } if(data1.contains(fname)!=false){ AlertDialog.Builder adb=new AlertDialog.Builder(context); adb.setTitle("My Records"); adb.setMessage(fname+" Already exist... do u want to overwrite???"); adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub try{ Statement statement2=connect.createStatement(); statement2.executeUpdate("UPDATE FORM1 SET NAME='"+fname+"',CITY='"+fcity+"' WHERE NAME='fname'"); }catch(Exception e){ Log.e("ERROR", e.getMessage()); } } }); adb.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); AlertDialog adbc=adb.create(); adbc.show(); } else{ Statement statement3=connect.createStatement(); statement3.executeUpdate("INSERT INTO FORM1(NAME,CITY) VALUES('"+name.getText().toString()+"','"+city.getText().toString()+"')"); } }catch(Exception e){ Log.e("ERROR", e.getMessage()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)