updateuserdatathread.java

来自「j2me实例代码」· Java 代码 · 共 56 行

JAVA
56
字号
package serverlet;

import javax.microedition.io.*;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class UpdateUserDataThread extends Thread {
	String url;
	public UpdateUserDataThread(String url,String id,String pw,String ds){
		String enc=System.getProperty("microedition.encoding");
		System.out.println("系统使用编码:"+enc);
		this.url=url+"?id="+id+"&pw="+pw+"&ds="+ds;
		System.out.println("url:"+this.url);
	}
	public void run(){
		boolean error=false;
		HttpConnection c=null;
		InputStream is=null;
		OutputStream os=null;
		DataInputStream dos=null;
		String line="";
		
		try{
			c=(HttpConnection)Connector.open(url);
			System.out.println("back code::"+c.getResponseCode());
			is=c.openInputStream();
			dos=new DataInputStream(is);
			line=dos.readUTF();
		}catch(EOFException e){
			System.out.println(".........:"+line);
		}catch(Exception e){
			error=true;
			Alert al=new Alert("更新时期发生错误",e.toString(),null,AlertType.ALARM);
			al.setTimeout(Alert.FOREVER);
			Navigator.display.setCurrent(al);
		}finally{
			try{
				if(is!=null)
					is.close();
				if(os!=null)
					os.close();
				if(c!=null)
					c.close();
			}catch(Exception e){}
		}
		if(!error){
			Alert al=new Alert("update result",line,null,AlertType.CONFIRMATION);
			al.setTimeout(Alert.FOREVER);
			Navigator.display.setCurrent(al);
		}
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?