Flex-Jsp-Mysql简单结合例子
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-12
|
数据库表 这个sql是用pd生成的,具体内容大家自己看一下好了,很简单,数据也自己填充一下。标题上说是用MySQL,其实无所谓用啥数据库了,这里我推荐Postgresql,现在有for win平台了,不用cygwin来模拟Unix环境,这个Postgresql一来小巧,二来功能齐全,看起来有点象Oracle,当然速度也很快了。
/*==============================================================*/
 /**//* Table: tblmobile */
 /**//*==============================================================*/
create table tblmobile
(
id integer(11) not null default 0,
categoryid integer(11),
name varchar(255),
image varchar(255),
price decimal(12,2),
addtime datetime,
primary key (id)
);

 /**//*==============================================================*/
 /**//* Index: i_tblMobile_categoryid */
 /**//*==============================================================*/
create index i_tblMobile_categoryid on tblmobile
(
categoryid
);

 /**//*==============================================================*/
 /**//* Index: pk_tblmobile */
 /**//*==============================================================*/
create unique index pk_tblmobile on tblmobile
(
id
);

 /**//*==============================================================*/
 /**//* Index: i_tblmobile_addtime */
 /**//*==============================================================*/
create index i_tblmobile_addtime on tblmobile
(
addtime
);
phonselist.JSP Jsp服务器用的是Tomcat,顺便做flex的服务器,版本没啥大关系,我现在用的是5.0.28,Jsp功能是按手机分类id从mysql数据库获取手机列表,这里为方便起见直接在jsp页面里进行数据库访问,正确的做法应该由Javabean来分工,其后总jsp生成的是一个XML文件。

<%@ page contentType="text/HTML;charset=utf-8"%>
<%@ page import="java.sql.*"%>

<%
String sql = ""
String url = ""

String categoryID = request.getParameter("categoryID");

try {
 Class .Class.forName("com.mysql.jdbc.Driver").newInstance();
url = "jdbc:mysql://localhost/web?user=flex&password=flex&useUnicode=true&characterEncoding=gb2312"
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();

sql = "select id, name, price, image from tblMobile where categoryid=" + categoryID;
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()){
out.println(""\">");
out.println("" + rs.getString(1) + "");
out.println("" + rs.getString(2) + "");
out.println("" + rs.getString(3) + "");
out.println("" + rs.getString(4) + "");
out.println("");
}

rs.close();
stmt.close();
conn.close();

} catch (Exception e) {
out.println(e);
}
%>

mobile.mxml 这里要注意一下中的resultFormat="xml"的设置,在这里应该把这个取掉(我原来 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|