Click here to Skip to main content
16,021,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello friends

i tried to create an android app which insert data to sql server using jdbc.
i want to apply a filter in insert method which notify user if he want to add same record again
i am using this code....but it is not working

Java
public void insert(){
	        	 try{
	        	 Statement statement=connect.createStatement();
	        	 String myname=name.getText().toString();
	        	 ResultSet result=statement.executeQuery("select * from form1 where name='"+name.getText().toString()+"'");
	        	 String lname=result.toString();
	        	if(myname==lname){
	        		AlertDialog adb=new AlertDialog.Builder(this).create();
	        		adb.setMessage("want to overwrite????");
	        		adb.setButton("ok", new DialogInterface.OnClickListener(
	        				) {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							try{
							Statement statement1=connect.createStatement();
							statement1.executeUpdate("insert into FORM1(NAME,CITY) " +
				                    "values('"+name.getText().toString() +"', '"+city.getText().toString()+"')");
				        statement1.close();
							}catch(Exception e){
								Log.e("ERROR", e.getMessage());
							}
							
							
						}
					});
	        		adb.setButton("No", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							
						}
					});
	        		adb.show();
	        		
	        	}
	        	else{
	        		 Statement statement2=connect.createStatement();
	 	        	
	 	        	statement2.executeUpdate("insert into FORM1(NAME,CITY) " +
	 	                    "values('"+name.getText().toString() +"', '"+city.getText().toString()+"')");
	 	        statement2.close();
	        	}
	         }catch(Exception e){
	        	 Log.e("ERROR", e.getMessage());
	        	
	         }
	         }


plzz guys tell me correct code...

it's very urgent......
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900