How to connect Android application to SQL Server through jbdc? -
i have tried connect android app sql server using jtds gives login error.
i have use jtds1.2.7-jar in libs folder
my code is:
public class mainact extends activity{ edittext e; button bt; listview lv; connection connect; simpleadapter sm; public void declere(){ e=(edittext)findviewbyid(r.id.et1); bt=(button)findviewbyid(r.id.bt1); lv=(listview)findviewbyid(r.id.list); } public void initilize(){ declere(); e.settext("select top 10 * form1"); connect=conn("sa","cbo@morc","kuldeep","122.160.255.218:1433"); } @suppresslint("newapi") private connection conn(string user,string pass,string db,string server){ strictmode.threadpolicy policy=new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); connection conn=null; string connurl=null; try{ class.forname("net.sourceforge.jtds.jdbc.driver"); connurl="jdbc:jtds:sqlserver://" + server + ";" + "databasename=" + db + ";user=" + user + ";passward=" + pass + ";"; conn=drivermanager.getconnection(connurl); }catch(sqlexception se){ log.e("error", se.getmessage()); }catch(classnotfoundexception cl){ log.e("error", cl.getmessage()); }catch(exception e){ log.e("error", e.getmessage()); } return conn; } public void querysql(string commandsql){ resultset rs; try{ statement statement=connect.createstatement(); rs=statement.executequery(commandsql); list<map<string,string>>data=null; data=new arraylist<map<string,string>>(); while(rs.next()){ map<string,string>datanum=new hashmap<string,string>(); datanum.put("a", rs.getstring("name")); datanum.put("b", rs.getstring("city")); data.add(datanum); } string [] from={"a","b"}; int [] to={r.id.tv1,r.id.tv2}; sm=new simpleadapter(this, data, r.layout.second, from, to); lv.setadapter(sm); }catch(exception e){ log.e("error", e.getmessage()); } } public void oncreate(bundle b){ super.oncreate(b); setcontentview(r.layout.main); initilize(); bt.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub querysql(e.gettext().tostring()); } }); } }
check passward
param in connection url. should password
?
Comments
Post a Comment