如何应用过滤器通过Android应用程序插入记录到sqlserver [英] how to apply filters in inserting records to sqlserver through android app

查看:88
本文介绍了如何应用过滤器通过Android应用程序插入记录到sqlserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友



i尝试创建一个使用jdbc将数据插入sql server的android应用程序。

i想要应用过滤器插入方法,如果他想再次添加相同的记录,通知用户

i am使用此代码....但它不工作



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

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家伙告诉我正确的代码......



非常紧急......



plzz guys tell me correct code...

it's very urgent......

推荐答案

查看一些例子..

http://stackoverflow.com/questions/5948736/filtering-query-in-database-sqlite [ ^ ]

http://stackoverflow.com/ questions / 9813758 / filtering-database-results-in-android-based-on-substring [ ^ ]

http://stackoverflow.com/questions/2591537/how-to-filter-android-database-by-column [ ^ ]
See some examples..
http://stackoverflow.com/questions/5948736/filtering-query-in-database-sqlite[^]
http://stackoverflow.com/questions/9813758/filtering-database-results-in-android-based-on-substring[^]
http://stackoverflow.com/questions/2591537/how-to-filter-android-database-by-column[^]


这篇关于如何应用过滤器通过Android应用程序插入记录到sqlserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆