package dao;
import java.sql.DriverManager;
import java.sql.ResultSet;
//import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class ConnMysql
{
private static String url="jdbc:mysql://localhost:3306/exam_lib"; //定义URL
private static String driver="com.mysql.jdbc.Driver"; //mysql-jdbc驱动程序
private static Connection conn=null;
private static ResultSet rs = null;
private static Statement st = null;
private static ResultSet rs2 = null;
private static Statement st2 = null;
public static Connection initConn()
{
try
{
//加载驱动程序
Class.forName(driver);
//连接数据库,需要用户名和密码
conn = DriverManager.getConnection(url,"root","33445xh5zj");
}
catch (Exception e)
{
e.printStackTrace();
}
return conn;
}
// public void AddTitle(String title) throws Exception
// {
// st = ConnMysql.initConn().createStatement();
// String sql;
// sql = "insert into cloze_content(title, content) values('" + title + "', '" + title + "')";
// st.executeUpdate(sql);
// }
// public int AddCloze(String title, int score, String content) throws Exception
// {
// st = ConnMysql.initConn().createStatement();
// String sql;
// sql = "insert into cloze_content(title, content, score) values('" + title + "', '" + content + "', " + score + ")";
// st.executeUpdate(sql);
// rs = st.executeQuery("select id from cloze_content order by id desc");
// rs.next();
// return rs.getInt("id");
// //rs.close();
// }
// public void AddClozeAll(String title, int score, String content, String[] option, int[] answer) throws Exception
// {
// //写入title和content(cloze_content表),并获取刚刚插入content的ID
// st = ConnMysql.initConn().createStatement();
// String sql;
// sql = "insert into cloze_content(title, content, score) values('" + title + "', '" + content + "', " + score + ")";
// st.executeUpdate(sql);
// rs = st.executeQuery("select id from cloze_content order by id desc");
// rs.next();
// int contentId = rs.getInt("id");
//
// System.out.println(contentId);
//
// //写入选项(cloze_option表)
// int choiceNum = 4;
//
// for(int i = 0; i <option.length; i++)
// {
// sql = "insert into cloze_option(content_id, question_id, option_content, is_answer) values(" + contentId + ", " + i/choiceNum + ", '" + option[i] + "', " + answer[i] + ")";
// st.executeUpdate(sql);
// }
// }
//添加一道完型填空题
public void AddClozeObj(ClozeInfo ci) throws Exception
{
System.out.println("执行函数");
//写入title和content(cloze_content表),并获取刚刚插入content的ID
st = ConnMysql.initConn().createStatement();
String sql;
sql = "insert into cloze_content(title, content, score) values('" + ci.getTitle() + "', '" + ci.getContent() + "', " + ci.getScore() + ")";
st.executeUpdate(sql);
rs = st.executeQuery("select id from cloze_content order by id desc");
rs.next();
int contentId = rs.getInt("id"); //获取刚刚插入的ID
System.out.println(contentId);
/*//输出测试
for(int j = 0; j < ci.getOptionList().size(); j++)
{
System.out.print(j + "abc--");
System.out.print(ci.getOptionList().get(j).getOption_content() + "-");
System.out.println(ci.getOptionList().get(j).getIs_answer());
}
*/
//写入选项(cloze_option表)
int optionNum = 4;
for(int i = 0; i < ci.getOptionList().size(); i++)
{
sql = "insert into cloze_option(content_id, question_id, option_content, is_answer) values(" + contentId + ", " + i/optionNum + ", '" + ci.getOptionList().get(i).getOption_content() + "', " + ci.getOptionList().get(i).getIs_answer()+ ")";
//sql = "insert into cloze_option(content_id, question_id, option_content, is_answer) values(" + contentId + ", " + i/optionNum + ", 'aaa', 1)";
st.executeUpdate(sql);
}
System.out.println("执行了函数");
rs.close();
st.close();
}
//获取所有题目列表(包含所有数据)
public List<ClozeInfo> GetClozeList(int pageSize, int page) throws Exception
{
List<ClozeInfo> ClozeList = new ArrayList<ClozeInfo>();
String sqlContent,sqlOption;
st = ConnMysql.initConn().createStatement();
st2 = ConnMysql.initConn().createStatement();
sqlContent = "select * from cloze_content order by id desc";
rs = st.executeQuery(sqlContent);
//逐一获取完型ClozeInfo对象
for(int i = 0; /*i < pageSize && */rs.next(); i++)
{
//获取title、content和score(cloze_content表)
ClozeInfo ci = new ClozeInfo();
ci.title = rs.getString("title");
ci.content = rs.getString("content");
ci.score = rs.getInt("score");
//获取选项和答案(cloze_option表)
sqlOption = "select * from cloze_option where content_id = " + rs.getInt("id");
rs2 = st2.executeQuery(sqlOption);
while(rs2.next())
{
ClozeOption co = new ClozeOption();
co.option_content = rs2.getString("option_content");
co.is_answer = rs2.getInt("is_answer");
ci.optionList.add(co);
}
//放入List数组
ClozeList.add(ci);
}
return ClozeList;
}
//获取一道题目全部数据
public ClozeInfo GetClozeObj(int clozeId) throws Exception
{
st = ConnMysql.initConn().createStatement();
String sql;
//查询短文标题、内容和分值
sql = "select * from cloze_content where id = " + clozeId;
rs = st.executeQuery(sql);
rs.next();
ClozeInfo ci = new ClozeInfo();
ci.title = rs.getString("title");
ci.content = rs.getString("content");
ci.score = rs.getInt("score");
//查询选项信息
sql = "select * from cloze_option where content_id = " + clozeId;
rs = st.executeQuery(sql);
while(rs.next())
{
ClozeOption co = new ClozeOption();
co.option_content = rs.getString("option_content");
co.is_answer = rs.getInt("is_answer");
ci.optionList.add(co);
}
return ci;
}
// public static void main(String[] args) throws Exception
// {
// ConnMysql cm = new ConnMysql();
// ClozeInfo ci = new ClozeInfo();
// ci = cm.GetClozeObj(108);
// //输出测试
// System.out.println("标题:"+ci.title+"\t内容:"+ci.content);
// for(int i = 0; i < ci.optionList.size(); i++)
// {
// System.out.print("选项:"+ci.optionList.get(i).option_content);
// System.out.println("答案:"+ci.optionList.get(i).is_answer);
// }
// cm.GetClozeList(20,1);
// //输出所有题目详细信息测试
// List<ClozeInfo> cl = new ArrayList<ClozeInfo>();
// cl = cm.GetClozeList(50, 1);
// for(int i = 0; i < cl.size(); i++)
// {
// System.out.println("标题:"+cl.get(i).title+"\t内容:"+cl.get(i).content+"\t分值:"+cl.get(i).score);
// for(int j = 0; j < cl.get(i).optionList.size(); j++)
// {
// System.out.print("选项:"+cl.get(i).optionList.get(j).option_content);
// System.out.println("答案:"+cl.get(i).optionList.get(j).is_answer);
// }
// }
// }
}
没有合适的资源?快使用搜索试试~ 我知道了~
Flex调用WebService的例子(完形填空考试系统)
共93个文件
mxml:16个
java:14个
html:10个
4星 · 超过85%的资源 需积分: 10 280 下载量 81 浏览量
2008-10-28
18:04:15
上传
评论 1
收藏 2.94MB RAR 举报
温馨提示
08年寒假在南京实习时写的东西,当时初学Flex,这是以Flex做客户端(界面),服务端用java写的,连mysql数据库。Flex通过WebService与java通信读取数据库中的试题。当时不懂WebService,在论坛里发了帖子询问,后来解决了,几个热心的朋友询问解决方法,这里共享出来,希望对初学的朋友们有些帮助。PS:现在已经不做Flex了,呵呵。
资源推荐
资源详情
资源评论
收起资源包目录
clozeTest.rar (93个子文件)
clozeTest
java_lib
.project 2KB
.myumldata 66B
.settings
com.genuitec.eclipse.ws.xfire.prefs 145B
.mymetadata 300B
WebRoot
WEB-INF
web.xml 621B
lib
classes
dao
ConnMysql.class 4KB
Temp.class 2KB
ClozeInfo.class 2KB
ClozeOption.class 984B
META-INF
xfire
services.xml 368B
model
service
IClozeService.class 434B
ClozeServiceImpl.class 1KB
META-INF
MANIFEST.MF 39B
.myeclipse
src
dao
Temp.java 1KB
ConnMysql.java 7KB
ClozeInfo.java 1KB
ClozeOption.java 735B
model
service
ClozeServiceImpl.java 689B
IClozeService.java 450B
WebServices
services.xml 368B
.classpath 439B
复件 src
dao
Temp.java 1KB
ConnMysql.java 5KB
ClozeInfo.java 2KB
model
service
ClozeServiceImpl.java 1KB
IClozeService.java 605B
flex_lib
.project 472B
bin
ClozeCreate.swf 488KB
tryTemp.swf 436KB
ClozeExerciseList.html 4KB
AC_OETags.js 8KB
ClozeExerciseList.swf 523KB
view
ClozeShowExercise.html 4KB
textTemp.swf 445KB
tryTemp.html 4KB
ClozeCreate.html 4KB
history
history.js 21KB
historyFrame.html 807B
history.css 371B
playerProductInstall.swf 657B
cloze
HelloWorld.swf 438KB
HelloWorld.html 4KB
temp.html 4KB
textTemp.html 4KB
ClozeShowExercise.swf 326KB
temp.swf 225KB
data
clozedata.xml 15KB
.settings
org.eclipse.core.resources.prefs 157B
libs
.actionScriptProperties 1KB
html-template
AC_OETags.js 8KB
index.template.html 4KB
history
history.js 21KB
historyFrame.html 807B
history.css 371B
playerProductInstall.swf 657B
src
dao
TakeResponder.as 392B
ClozeOption.as 282B
ClozeDao.as 738B
ClozeInfo.as 236B
temp.mxml 142B
textTemp.mxml 956B
ClozeCreate.mxml 6KB
tryTemp.mxml 1KB
Cloze.mxml 302B
data
clozedata.xml 15KB
ClozeShowExercise.mxml 2KB
util
Func.as 871B
ClozeExerciseList.mxml 3KB
doc
完形填空.doc 48KB
完型填空-数据库设计.doc 51KB
数据库设计-Mysql.doc 376KB
复件 src
dao
ClozeOption.as 159B
ClozeDao.as 728B
ClozeInfo.as 214B
temp.mxml 142B
复件 ClozeShowExercise.mxml 4KB
ClozeCreate.mxml 6KB
tryTemp.mxml 1KB
复件 ClozeExerciseList.mxml 1KB
Cloze.mxml 302B
复件 ClozeCreate.mxml 7KB
data
clozedata.xml 15KB
ClozeShowExercise.mxml 4KB
util
Func.as 871B
ClozeExerciseList.mxml 2KB
.flexProperties 134B
java_libBak
ConnMysql.class 2KB
queryData.jsp 0B
ConnMysql.java 1KB
DBConnBean.java 3KB
DBQueryBean.java 2KB
DBConnBean.class 5KB
DBQueryBean.class 3KB
共 93 条
- 1
libodls
- 粉丝: 30
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页