package dao;
import java.sql.*;
import utils.DB_Connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import bean.course1;
import bean.sc1;
import bean.stu1;
import bean1.course2;
import bean1.sc2;
import bean1.stu2;
import xml.DOMxml;
import utils.DB_Connection;
public class ScDaoImpl {
static //初始化预编译对象,结果集,数据库连接
Statement state = null;
static int rs = 0;
static Connection conn = null;
static //工具包中的数据库连接方法
DB_Connection db = new DB_Connection();
static DOMxml doc = new DOMxml();
public static void getDOM() throws Exception {
doc.Num();
doc.CreateWeb();
doc.UniformField();
doc.AllFields();
}
public static ArrayList<sc1> findsc1(String sid,int j) throws Exception
{//按学号查找成绩
//获取连接
Connection conn=db.getConnection(db.geturl(doc.getDbTable().get(j).get(0)));
if(conn!=null){
System.out.println("连接正常!");
}else{
System.out.println("连接异常!");
}
Statement state =null;
ResultSet rs = null;
ArrayList<sc1> list=new ArrayList<sc1>();
try{
String sql = "select "+doc.getDbTable().get(j).get(3)+".* from "+doc.getDbTable().get(j).get(3)+" ,"+doc.getDbTable().get(j).get(1)+", "+doc.getDbTable().get(j).get(2)+" where "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(0)+"="+doc.getDbTable().get(j).get(1)+"."+doc.getAllFiled().get(j).get(0).get(0)+" and "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(1)+"="+doc.getDbTable().get(j).get(2)+"."+doc.getAllFiled().get(j).get(1).get(0)+" and "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(0)+" = '"+sid+"'";
state = conn.createStatement();
rs=state.executeQuery(sql);
while(rs.next())
{
sc1 sc=new sc1();
sc.setCid(rs.getString(doc.getAllFiled().get(j).get(2).get(1)));
sc.setSid(rs.getString(doc.getAllFiled().get(j).get(2).get(0)));
sc.setScore(rs.getInt(doc.getAllFiled().get(j).get(2).get(2)));
list.add(sc);
}
}catch(Exception e){
e.printStackTrace();
}finally{
conn.close();
}
return list;
}
public static ArrayList<sc1> findsc2(String cid,int j) throws Exception
{//按课程号查找成绩
//获取连接
Connection conn=db.getConnection(db.geturl(doc.getDbTable().get(j).get(0)));
/*if(conn!=null){
System.out.println("连接正常!");
}else{
System.out.println("连接异常!");
}*/
Statement state =null;
ResultSet rs = null;
ArrayList<sc1> list=new ArrayList<sc1>();
try{
String sql = "select "+doc.getDbTable().get(j).get(3)+".* from "+doc.getDbTable().get(j).get(3)+" ,"+doc.getDbTable().get(j).get(1)+", "+doc.getDbTable().get(j).get(2)+" where "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(0)+"="+doc.getDbTable().get(j).get(1)+"."+doc.getAllFiled().get(j).get(0).get(0)+" and "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(1)+"="+doc.getDbTable().get(j).get(2)+"."+doc.getAllFiled().get(j).get(1).get(0)+" and "+doc.getDbTable().get(j).get(3)+"."+doc.getAllFiled().get(j).get(2).get(1)+" = '"+cid+"'";
state = conn.createStatement();
rs=state.executeQuery(sql);
while(rs.next())
{
sc1 sc=new sc1();
sc.setCid(rs.getString(doc.getAllFiled().get(j).get(2).get(1)));
sc.setSid(rs.getString(doc.getAllFiled().get(j).get(2).get(0)));
sc.setScore(rs.getInt(doc.getAllFiled().get(j).get(2).get(2)));
list.add(sc);
}
}catch(Exception e){
e.printStackTrace();
}finally{
conn.close();
}
return list;
}
public static int addsc(String sid,String cid,int score,int j) throws Exception{//根据sid,cid添加
//获取连接
Connection conn=db.getConnection(db.geturl(doc.getDbTable().get(j).get(0)));
try {
String sql = "insert into "+doc.getDbTable().get(j).get(3)+"("+doc.getAllFiled().get(j).get(2).get(0)+","+doc.getAllFiled().get(j).get(2).get(1)+","+doc.getAllFiled().get(j).get(2).get(2)+") values ('"+sid+"','"+cid+"','"+score+"')";
// 预编译sql
state = conn.createStatement();
//更新结果集
rs = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}finally {
//释放资源
conn.close();
}
return rs;
}
public static int updatesc(String sid,String cid,int score,int j) throws Exception{//根据sid,cid修改score
//获取连接
Connection conn=db.getConnection(db.geturl(doc.getDbTable().get(j).get(0)));
try {
String sql = "update "+doc.getDbTable().get(j).get(3)+" set "+doc.getAllFiled().get(j).get(2).get(2)+"='"+score+"' where "+doc.getAllFiled().get(j).get(2).get(0)+" = '"+sid+"' and "+doc.getAllFiled().get(j).get(2).get(1)+"='"+cid+"'";
// 预编译sql
state = conn.createStatement();
//更新结果集
rs = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}finally {
//释放资源
conn.close();
}
return rs;
}
public static int deletesc1(String stid,String coid,int j) throws Exception{//根据sid,cid删除
//获取连接
Connection conn=db.getConnection(db.geturl(doc.getDbTable().get(j).get(0)));
try {
String sql = "delete from "+doc.getDbTable().get(j).get(3)+" where "+doc.getAllFiled().get(j).get(2).get(0)+" = '"+stid+"' and "+doc.getAllFiled().get(j).get(2).get(1)+"='"+coid+"'";
// 预编译sql
state = conn.createStatement();
//更新结果集
rs = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}finally {
//释放资源
conn.close();
}
return rs;
}
/*public static void main(String[] args) {
try {
UserDaoImpl u =new UserDaoImpl();
try {
ScDaoImpl.getDOM();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ArrayList<sc1> stus =new ArrayList<sc1>();
ScDaoImpl c=new ScDaoImpl();
stus=c.findsc1("111", 1);
for(int i=0;i<stus.size();i++) {
System.out.println(stus.get(i).getScore());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
}
/*
public static ArrayList<sc2> findsc22(int coid) throws Exception
{//按课程号查找成绩
//获取连接
conn = db.getConnection1();
Statement state =null;
ResultSet rs = null;
ArrayList<sc2> list=new ArrayList<sc2>();
try{
String sql = "select sc2.* from sc2 ,stu2, course2 where sc2.stid=stu2.stid and sc2.coid=course2.coid and sc2.coid = "+coid+"";
state = conn.createStatement();
rs=state.executeQuery(sql);
while(rs.next())
{
sc2 sc=new sc2();
sc.setCid(rs.getInt("coid"));
sc.setSid(rs.getInt("stid"));
sc.setScore(rs.getInt("grade"));
list.add(sc);
}
}catch(Exception e){
e.printStackTrace();
}finally{
conn.close();
}
return list;
}
//学生1
public static int addsc1(String stid,int coid,int grade) throws Exception{
//获取连接
conn = db.getConnection1();
try {
String sql = "insert into sc2(stid,coid,grade) values ('"+stid+"','"+coid+"','"+grade+"')";
// 预编译sql
state = conn.createStatement();
//更新结果集
rs = state.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}finally {
//释放资源
conn.close();
}
return rs;
}
public static int updatesc1(String stid,int
没有合适的资源?快使用搜索试试~ 我知道了~
应用集成学生管理系统源码
共24个文件
java:20个
xml:3个
properties:1个
需积分: 0 1 下载量 195 浏览量
2023-12-19
20:58:40
上传
评论
收藏 20KB ZIP 举报
温馨提示
核心部分的源码
资源推荐
资源详情
资源评论
收起资源包目录
应用集成学生管理系统源码.zip (24个子文件)
src
controller
deletesc.java 3KB
updatescore.java 3KB
showsore.java 4KB
exit.java 943B
ScServlet.java 3KB
message.java 2KB
LoginServlet.java 1KB
utils
DB_Connection.java 2KB
config.properties 430B
dao
UserDaoImpl.java 3KB
CourseDao.java 2KB
ScDaoImpl.java 9KB
StudentDao.java 2KB
ScCollection.java 4KB
bean1
stu2.java 574B
course2.java 594B
sc2.java 665B
xml
2.xml 1KB
DOMxml.java 7KB
1.xml 1KB
student.xml 532B
bean
stu1.java 529B
course1.java 536B
sc1.java 602B
共 24 条
- 1
资源评论
yxbkl
- 粉丝: 50
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功