XPY 2011-09-16
网络彩讯既然是通过云平台实现滴,那当然需要数据的存储以及文件的存储了。
对于本地,什么数据库都没使用到,仅仅是下载的彩讯会保存到本地,而发送的在发送完后都在本地删除了、
下面就来见识见识云平台数据的传输吧,在速度上,本人经测试是一般网络速度的两倍多点吧、
核心类:
需要x5cloud云平台提供的账号,就像你看到的16个8
然后是数据库的选择:看那个1,代表的是mysql
接着是你创建的数据库:比如Android_CX
最后出场的,也是最重要的服务器域名了:看吧,service.x5cloud.com
public class DataBase { private static String userid="8888888888888888"; private static int dbtype=1; private static String dbname="Android_CX"; private static String serverip="service.x5cloud.com"; private static List<String> sql=new ArrayList<String>(); public void clearSql() { sql.clear(); } public List<String> getSql() { return sql; } public void addSql(String elsql){ sql.add(elsql); } public boolean doData(List<String> sql){ int istransaction=1; X5Persist x5=new X5Persist(userid,dbtype,dbname,serverip); boolean flag=false; try { flag = x5.x5job(sql,istransaction); } catch (X5Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } if(flag){ System.out.println("成功!"); } return flag; } public X5DBResult searchData(String sql){ X5Persist x5=new X5Persist(userid,dbtype,dbname,serverip); X5DBResult rs = null; try { rs = x5.select(sql); return rs; } catch (X5Exception e) { e.printStackTrace(); } return null; } public boolean handleDate(List<String> sql){ int istransaction=1; X5Persist x5=new X5Persist(userid,dbtype,dbname,serverip); boolean flag=false; try { flag = x5.x5job(sql,istransaction); } catch (X5Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return flag; } }
好了,废话少说,看代码!
public boolean register(String name, String password, String code) { DataBase db = new DataBase(); String[] elsql = new String[10]; elsql[0] = "insert into users(Name,Password,CheckCode) values('" + name + "','" + password + "','" + code + "')"; db.addSql(elsql[0]); boolean BL = db.doData(db.getSql()); db.clearSql(); return BL; } public boolean checkData(String name, String str, int number) { DataBase db = new DataBase(); final String sql; if (number == 0) { sql = "select * from users where users.Name='" + name + "' and users.Password='" + str + "'"; } else { sql = "select * from users where users.Name='" + name + "' and users.CheckCode='" + str + "'"; } X5DBResult rs = db.searchData(sql); boolean BL = true; if (rs.hasNext()) BL = false; return BL; }
以上就是登录注册时和云平台接触的code,是不是非常简单!对!就是这么简单!