0
回答
andriod下通过webservice 加SQL数据库判断用户名和密码
终于搞明白,存储TCO原来是这样算的>>>   

andriod下通过webservice 加SQL数据库判断登录用户名和密码;请大家帮我检查下,谢谢

下面是MainActivity在下判断,问题主要出在dbUtil.JudgeUserInfo("111","9999", "SL"); 这句的调用里面;

public class MainActivity extends Activity {
    private Button btnlogin;
    private DBUtil dbUtil;   
    private boolean lgstate;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		btnlogin=(Button) findViewById(R.id.login);
		btnlogin.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v){           		

				setJudgeUser();
    				if(lgstate==true)
    				{
    				//用户存在打开新窗口
    				Intent intent=new Intent();
    				EditText editText=(EditText)findViewById(R.id.et_username);
    				intent.setClass(MainActivity.this, Childmain.class);
    				intent.putExtra("username",editText.getText().toString());//技师编号
    				startActivityForResult(intent, 0);
    				}
    				else
    				{
    					Toast.makeText(MainActivity.this, "登录失败,用户名或密码有误!", Toast.LENGTH_LONG).show(); 
    				}
    				
            		}
	}

    /** 
     * 判断传人的用户信息是否正确
     */
	public void setJudgeUser() {  
		dbUtil.JudgeUserInfo("111","9999", "SL"); 
		lgstate=true;
    }

下面是DBUtil的代码;

public class DBUtil {
    private ArrayList<String> arrayList = new ArrayList<String>();  
    private ArrayList<String> brrayList = new ArrayList<String>();  
    private ArrayList<String> crrayList = new ArrayList<String>();  
    private HttpConnSoap Soap = new HttpConnSoap();  
    
    public static Connection getConnection() {  
        Connection con = null;  
        try {  
            //Class.forName("org.gjt.mm.mysql.Driver");   
            //con=DriverManager.getConnection("jdbc:sqlserver://192.168.0.106:3306/test?useUnicode=true&characterEncoding=UTF-8","root","initial");                
        } catch (Exception e) {  
            //e.printStackTrace();   
        }  
        return con;  
    }  
  
    /** 
     * 判断传人的用户信息是否存在 
     *  
     * @return 
     */  
    public void JudgeUserInfo(String TechNum, String Anpassword, String CmpCode) {  
  
        arrayList.clear();  
        brrayList.clear();  
          
        arrayList.add("TechNum");  
        arrayList.add("Anpassword"); 
        arrayList.add("CmpCode"); 
        brrayList.add(TechNum);  
        brrayList.add(Anpassword); 
        brrayList.add(CmpCode);
          
        Soap.GetWebServre("JudgeUserInfo", arrayList, brrayList).getClass();  
    }  
    

}

下面是HttpConnSoap Soap的代码

public class HttpConnSoap {
	public ArrayList<String> GetWebServre(String methodName, ArrayList<String> Parameters, ArrayList<String> ParValues) {  
        ArrayList<String> Values = new ArrayList<String>();  
          
       String ServerUrl = "http://10.10.0.21/Kanglesystem/KlService.asmx";  
          
        String soapAction = "http://tempuri.org/" + methodName;  
        String soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"  
                + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"  
                + "<soap:Body />";  
        String tps, vps, ts;  
        String mreakString = "";  
  
        mreakString = "<" + methodName + " xmlns=\"http://tempuri.org/\">";  
        for (int i = 0; i < Parameters.size(); i++) {  
            tps = Parameters.get(i).toString();  
            //设置该方法的参数为.net webService中的参数名称   
            vps = ParValues.get(i).toString();  
            ts = "<" + tps + ">" + vps + "</" + tps + ">";  
            mreakString = mreakString + ts;  
        }  
        mreakString = mreakString + "</" + methodName + ">";  
        /* 
        +"<HelloWorld xmlns=\"http://tempuri.org/\">" 
        +"<x>string11661</x>" 
        +"<SF1>string111</SF1>" 
        + "</HelloWorld>" 
        */  
        String soap2 = "</soap:Envelope>";  
        String requestData = soap + mreakString + soap2;  
 
        try {  
            URL url = new URL(ServerUrl);  
            HttpURLConnection con = (HttpURLConnection) url.openConnection();  
            byte[] bytes = requestData.getBytes("utf-8");  
            con.setDoInput(true);  
            con.setDoOutput(true);  
            con.setUseCaches(false);  
            con.setConnectTimeout(6000);// 设置超时时间   
            con.setRequestMethod("POST");  
            con.setRequestProperty("Content-Type", "text/xml;charset=utf-8");  
            con.setRequestProperty("SOAPAction", soapAction);  
            con.setRequestProperty("Content-Length", "" + bytes.length);  
            OutputStream outStream = con.getOutputStream();  
            outStream.write(bytes);  
            outStream.flush();  
            outStream.close();  
            InputStream inStream = con.getInputStream();  
  
            Values = inputStreamtovaluelist(inStream, methodName);    
            return Values;  
  
        } catch (Exception e) {  
            return null;  
        } 
	}
        
        public ArrayList<String> inputStreamtovaluelist(InputStream in, String MonthsName) throws IOException {  
            StringBuffer out = new StringBuffer();  
            String s1 = "";  
            byte[] b = new byte[4096];  
            ArrayList<String> Values = new ArrayList<String>();  
            Values.clear();  
      
            for (int n; (n = in.read(b)) != -1;) {  
                s1 = new String(b, 0, n);  
                out.append(s1);  
            }  
      
            System.out.println(out);  
            String[] s13 = out.toString().split("><");
            String ifString = MonthsName + "Result";  
            String TS = "";  
            String vs = "";  
      
            Boolean getValueBoolean = false;  
            for (int i = 0; i < s13.length; i++) {  
                TS = s13[i];  
                System.out.println(TS);  
                int j, k, l;  
                j = TS.indexOf(ifString);  
                k = TS.lastIndexOf(ifString);  
      
                if (j >= 0) {  
                    System.out.println(j);  
                    if (getValueBoolean == false) {  
                        getValueBoolean = true;  
                    } else {  
      
                    }  
      
                    if ((j >= 0) && (k > j)) {  
                        System.out.println("FFF" + TS.lastIndexOf("/" + ifString));  
                        l = ifString.length() + 1;  
                        vs = TS.substring(j + l, k - 2);  
                        Values.add(vs);  
                        System.out.println("退出" + vs);  
                        getValueBoolean = false;  
                        return Values;  
                    }  
      
                }  
                if (TS.lastIndexOf("/" + ifString) >= 0) {  
                    getValueBoolean = false;  
                    return Values;  
                }  
                if ((getValueBoolean) && (TS.lastIndexOf("/" + ifString) < 0) && (j < 0)) {  
                    k = TS.length();  
                    vs = TS.substring(7, k - 8);   
                    Values.add(vs);  
                }        
            }  
      
            return Values;  
        }  

}

 

举报
xiaowg
发帖于4年前 0回/554阅
顶部