gwt ext 连接MySql数据库
该连接方式采用RPC来返回数据库查询结果。
1.首先是创建普通的GWT-EXT工程。可以参考1http://www.ibm.com/developerworks/cn/java/j-lo-gwtext1/#resources
系列 入 门 教程。具体通讯过程服务也可参考上述的最后部分说明。
2. 接下来就是要创建GWT Remote Service了,在原有工程上new->Other->GWT Remote Service 。如图1:
图1
新建一个GWT Remote Service如下图2:
图2
完成输入确定后,GWT会自动在clent端和server端生成需要的文件。如下图3阴影部分文件:
3.完成了基本配置后,我们要写需要实现的代码;
本人数据库为student;为了简单只有3列,sno,name,sex三项。
a.在DbService里实现getInstance(),实现通讯功能。具体见参考1.
代码如下:
package zjm.DbBase.demo.client;
import java.util.List;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
@RemoteServiceRelativePath("DbService")
public interface DbService extends RemoteService {
public List<DTO> loadData()throws Exception;
public static final String SERVICE_URI = "DbService";
public static class Util {
public static DbServiceAsync getInstance() {
DbServiceAsync instance = (DbServiceAsync) GWT
.create(DbService.class);
ServiceDefTarget target = (ServiceDefTarget) instance;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + SERVICE_URI);
return instance;
}
}
}
其中public List<DTO> 方法是自己定义来获取数据库数据的方法。这个方法需要在DbServiceImpl.java中实现。该类实现了DbService这个服务接口。
b. DbServiceImpl.java代码实现上述方法:
代码:
package zjm.DbBase.demo.server;
import java.sql.DriverManager;
import java.util.LinkedList;
import java.util.List;
import zjm.DbBase.demo.client.DTO;
import zjm.DbBase.demo.client.DbService;
i
相关文档:
地址: http://imysql.cn/taxonomy/term/1?page=1
[InnoDB系列] -- innodb表如何更快得到count(*)结果:http://imysql.cn/2008_06_24_speedup_innodb_count
[InnoDB系列系列] -- 大数据量的导出导入方法比较:
http://imysql.cn/2007_10_15_large_innodb_table_export_import
[MySQL优化案例]系列 -- DISABLE/ENABLE K ......
//主键
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//删除列
alter table t2 drop column c;
//重命名列
......
MySQL的datetime设置当前时间为默认值
由于MySQL目前字段的默认值不支持函数,所以用
create_time datetime default now()
的形式设置默认值是不可能的。
代替的方案是使用TIMESTAMP类型代替DATETIME类型。
CURRENT_TIMESTAMP :当我更新这条记录的时候,这条记录的这个字段不会改变
。
CURRENT_TIMESTAMP O ......
#
-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
#
连接数据库
try
:
conn
=
MySQLdb.connect(host
=
'
localhost
'
,user
=
'
root
'
,passwd
=
'
xxxx
'
,db
=
'
test1
'
)
except
Exception, e:
print
e
sys.exit()
......