package com.hibernate.query;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import com.hibernate.model.*;
public class DBquery {
public SessionFactory sf=new AnnotationConfiguration().configure().buildSessionFactory();
// public List<Tinfo> querytinfo(){
// Session sn=sf.openSession();
// sn.beginTransaction();
// Query q=sn.createQuery("from Tinfo ");
// List<Tinfo> tinfos=(List<Tinfo>)q.list();
// sn.getTransaction().commit();
// sn.close();
// return tinfos;
//
public List<Question> queryquestions(){
Session sn=sf.openSession();
sn.beginTransaction();
Query q=sn.createQuery("from Question");
List<Question> questions= (List<Question>) q.list();
sn.getTransaction().commit();
sn.close();
return questions;
}
public List<Answer> querytester_answer(int i){//取出某一测试者答案
Session sn=sf.openSession();
sn.beginTransaction();
Query q=sn.createQuery("from Answer answer where answer.tid="+i);
List<Answer> as= (List<Answer>) q.list();
sn.getTransaction().commit();
sn.close();
return as;
}
public void saveanswer(Answer asw){//存储答案对象
Session sn=sf.openSession();
sn.beginTransaction();
sn.save(asw);
sn.getTransaction().commit();
sn.close();
}
public int savetester(Tester t){ //存储测试者对象
Session sn=sf.openSession();
sn.beginTransaction();
sn.save(t);
sn.getTransaction().commit();
int i=t.getTid();
sn.close();
return i;
}
public int queryqnum(){//取出问题总数
List<Question> qs=new ArrayList<Question>();
qs=this.queryquestions();
int i=qs.size();
return i;
}
public int counttester(){//获取测试者人数
Session sn=sf.openSession();
sn.beginTransaction();
Query q=sn.createQuery("from Tester");
List<Tester> ts= (List<Tester>) q.list();
sn.getTransaction().commit();
sn.close();
return ts.size();
}
public void caddone(int cid){//某一选项加一个支持加一
Session sn=sf.openSession();
sn.beginTransaction();
Choice c=new Choice();
c=(Choice)sn.get(Choice.class, cid);
int i=c.getTimes();
i=i+1;
c.setTimes(i);
sn.save(c);
sn.getTransaction().commit();
sn.close();
}
public void updatepercent(){//更新全部选项的百分比
Session sn=sf.openSession();
sn.beginTransaction();
List<Choice> cs=new ArrayList<Choice>();
cs=( List<Choice> )sn.createQuery("from Choice").list();
double alltester=(double)this.counttester();
for(Choice c:cs){
double times=(double)c.getTimes();
String percent=this.decimal(times, alltester);
c.setPercentage(percent);
sn.save(c);
}
sn.getTransaction().commit();
sn.close();
}
public String decimal(double x,double y) {
double z = x/y;
DecimalFormat myformat = null;
myformat= (DecimalFormat)NumberFormat.getPercentInstance();
myformat.applyPattern("00.00%");//设置百分率的输出形式,形如00.*,根据需要设定。
String percentage=myformat.format(z);
return percentage;
}
public Tester querytinfo(int tid){
Session sn=sf.openSession();
sn.beginTransaction();
Tester tinfo=(Tester)sn.createQuery("from Tester t where t.tid="+tid).uniqueResult();
sn.getTransaction().commit();
sn.close();
return tinfo;
}
public List<Tester> queryts(){
Session sn=sf.openSession();
sn.beginTransaction();
List<Tester> testers=(List<Tester>)sn.createQuery("from Tester ").list();
sn.getTransaction().commit();
sn.close();
return testers;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java web的网上问卷调查系统(源码+数据库).zip
共56个文件
jar:11个
class:9个
java:9个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 136 浏览量
2022-12-13
15:11:34
上传
评论
收藏 3.3MB ZIP 举报
温馨提示
网上问卷调查系统,使用说明:用Java ee工具打开系统源码,脚本导入MySQL数据库,修改数据库连接语句,即可运行
资源推荐
资源详情
资源评论
收起资源包目录
基于Java web的网上问卷调查系统(源码+数据库).zip (56个子文件)
在线调查问卷
Research_Project
.settings
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 629B
src
log4j.properties 2KB
com
hibernate
model
Question.java 962B
Choice.java 1KB
Tester.java 612B
Answer.java 758B
test
test.java 1KB
query
DBquery.java 4KB
struts
action
QuestionAction.java 937B
TanswerAction.java 4KB
Cdb.java 579B
struts.xml 1KB
hibernate.cfg.xml 2KB
.project 1KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 658B
classes
log4j.properties 2KB
com
hibernate
model
Question.class 2KB
Choice.class 2KB
Tester.class 1KB
Answer.class 1KB
test
test.class 3KB
query
DBquery.class 5KB
struts
action
QuestionAction.class 2KB
TanswerAction.class 6KB
Cdb.class 1KB
struts.xml 1KB
hibernate.cfg.xml 2KB
lib
asm-tree-3.1.jar 21KB
javassist-3.11.0.GA.jar 600KB
ognl-3.0.1.jar 224KB
asm-3.1.jar 42KB
commons-io-2.0.1.jar 156KB
freemarker-2.3.16.jar 860KB
commons-fileupload-1.2.2.jar 58KB
xwork-core-2.2.3.jar 602KB
commons-lang-2.5.jar 273KB
asm-commons-3.1.jar 32KB
struts2-core-2.2.3.jar 756KB
result
Question_listqs_success.jsp 3KB
Tanswer_saveanswer_success.jsp 2KB
thx.gif 9KB
thx2.gif 12KB
Tanswer_querysum_success.jsp 2KB
Tanswer_queryta_success.jsp 2KB
page
addfile.jsp 1KB
addteacher.jsp 984B
index.jsp 1016B
test.jsp 1KB
.mymetadata 322B
.classpath 1KB
.myeclipse
research_project.sql 6KB
共 56 条
- 1
资源评论
等天晴i
- 粉丝: 5278
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于LUT查找表方法的正弦信号产生器FPGA实现,包含testbench,包括程序,注释,操作步骤
- Screenshot_20240618_174113.jpg
- matlab画正余弦函数图的代码!!!!!
- 2_期末网店运营报告模版.pdf
- MyBatisCodeHelperPro 3.3.2-2322 2023.2-2024.1
- 基于Python的简单的学生成绩管理程序设计(课程设计)
- jdk-8u20-windows-x64安装版本-jdk-8u301-linux-x64解压版
- 植物大战僵尸杂交版 修改阳光和冷却
- html css js网页设计ntion-model-for-开发笔记
- 数据库课程设计-processing开发笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功