|
|

Este post foi editado pela última vez por Delver_Si em 20-11-2014 às 21:21
[mw_shl_code=sql,true]use master Vai if exists(selecione * em sys.databases onde nome = 'escola') Escola de Banco de Dados de Drop Vai Criar Escola de Banco de Dados Vai Usar a escola Vai criar aluno de tabela
( stu_id varchar(10) número ,-- chave primária stu_name varchar(20) não nulo,-- nome stu_addr Varchar (100) ,-- endereço stu_spec Varchar (50) ,-- profissional stu_dorm Varchar (50) — Dormitório
) Vai inserir nos valores estudantis ('100001', 'Zhang San', 'Wuhan Xu Dong', 'Engenharia da Informação', '101') inserir nos valores estudantis ('100002', 'Li Si', 'Wuhan Xu Dong', 'Engenharia de Informação', '102')
Selecionar * do estudante
--delete do estudante onde stu_id = '100001'
--atualizar conjunto de alunos stu_name = 'Li Si', stu_addr = 'Zhang San', stu_spec= 'Testes de Software', stu_dorm = '1001' onde stu_id = '100001'[/mw_shl_code]
[mw_shl_code=java,true]pacote online.school.test;
importar java.util.ArrayList; import java.util.List; importar online.school.domain.Student; importar online.school.service.StudentService;
classe pública StudentTest {
public static void main(String[] args) { novo StudentTest().getAllStudent(); } public int addStudent() { Estudante estudante = novo estudante ("3", "Wang Wu", "Xiaogan", "Testes de Software", "103"); return new StudentService().addStudent(student); }
public int delStudent() { String stuId="3"; return new StudentService().delStudent(stuId); }
public void findStudent() { String stuId="3"; Estudante estudante =novo StudentService().findStudent(stuId); System.out.println(student.toString()); }
public<Student> List getAllStudent() { ArrayList al = (ArrayList) novo StudentService().getAllStudent(); for(int i =0; i<al.size(); i++){ Objecto[] obj =(Objeto[]) al.get(i); for(int j=0; j<5; j++){ System.out.print(obj[j] + " "); } System.out.println(); } Retorne Al; }
public int updateStudent() {
Estudante estudante = novo estudante ("3", "Wang Wu", "Yingcheng", "Engenharia Civil", "103"); novo StudentService().updateStudent(student); retorno 0;
}
} [/mw_shl_code]
[mw_shl_code=java,true]pacote online.school.domain;
classe pública Estudante {
soldado String stu_id; Número soldado String stu_name; Nome soldado String stu_addr; - Endereço soldado String stu_spec; Carreira profissional soldado String stu_dorm; Dormitório Public String getStu_id() { retorno stu_id; } empty público setStu_id(String stuId) { stu_id = stuId; } Public String getStu_name() { retorno stu_name; } empty public void setStu_name(String stuName) { stu_name = stuName; } Public String getStu_addr() { retorno stu_addr; } público vazio setStu_addr(String stuAddr) { stu_addr = stuAddr; } Public String getStu_spec() { retorno stu_spec; } empty público setStu_spec(String stuSpec) { stu_spec = stuSpec; } Public String getStu_dorm() { retorno stu_dorm; } vazio-público setStu_dorm(String stuDorm) { stu_dorm = stuDorm; }
public Student() { super(); } Public Student(String stuId, String stuName, String stuAddr, String stuSpec, String stuDorm) { super(); stu_id = stuId; stu_name = stuName; stu_addr = stuAddr; stu_spec = stuSpec; stu_dorm = stuDorm; } @Override public String toString() { retorne "Estudante [stu_addr=" + stu_addr + ", stu_dorm=" + stu_dorm + ", stu_id=" + stu_id + ", stu_name=" + stu_name + ", stu_spec=" + stu_spec + "]"; }
} [/mw_shl_code] [mw_shl_code=java,true]pacote online.school.service;
import java.util.List;
importar online.school.dao.StudentDao; importar online.school.domain.Student; importar online.school.utils.SqlHelp;
a classe pública StudentService implementa IStudentService{
@Override public int addStudent(Student student) {
String sql = "inserir nos valores do aluno(?,?,?,?,?)"; return new StudentDao().addStudent(sql,student.getStu_id(),student.getStu_name(),student.getStu_addr(),student.getStu_spec(),student.getStu_dorm()); }
@Override public int delStudent(String stuId) { String sql = "excluir do estudante onde stu_id = ?"; return new StudentDao().delStudent(sql, stuId); }
@Override public Student findStudent(String stuId) { String sql = "selecione * do estudante onde stu_id = ?"; return new StudentDao().findStudent(sql, stuId); }
@Override public<Student> List getAllStudent() { String sql = "selecionar * do estudante"; return new StudentDao().getAllStudent(sql); }
@Override atualização pública intStudent(Student student) { String sql = "atualizar conjunto de alunos stu_name = ?,stu_addr = ?, stu_spec= ?,stu_dorm = ? onde stu_id = ?"; return new StudentDao().updateStudent(sql, student.getStu_name(),student.getStu_addr(),student.getStu_spec(),student.getStu_dorm(),student.getStu_id());
}
} [/mw_shl_code] [mw_shl_code=java,true]pacote online.school.dao;
importar java.util.ArrayList; import java.util.List; importar online.school.domain.Student; importar online.school.utils.SqlHelp;
classe pública StudentDao implementa IStudentDao{
@Override public int addStudent(String sql, String... args) { return new SqlHelp().executeUpdate(sql,args);
}
@Override public int delStudent (String sql, String... args) { return new SqlHelp().executeUpdate(sql,args); }
@Override Estudante público findStudent (String sql, String... args) { ArrayList al = new SqlHelp().executeQuery(sql, args); Object[] obj =(Objecto[]) al.get(0); Estudante estudante = novo estudante(); student.setStu_id((Corda) obj[0]); student.setStu_name((Corda) obj[1]); student.setStu_addr((Corda) obj[2]); student.setStu_spec((Corda) obj[3]); student.setStu_dorm((Corda) obj[4]); aluno retornado;
}
@Override public List<Student> getAllStudent(String sql) {
ArrayList al = new SqlHelp().executeQuery(sql); Retorne Al; }
@Override atualização pública intStudent(String sql, String... args) {
return new SqlHelp().executeUpdate(sql, args);
}
} [/mw_shl_code]
|
-
-
stuManager.rar
507,45 KB, Tempos de download: 0, Créditos de download: -1 prestígio, -1 contribuição
Preço de Venda:2 MB [Gravação]
[compra]
Anterior:Recentemente, estou fazendo um projeto em uma livraria online, que é uma função de registro que tem sido feita nos últimos diasPróximo:Versão C# do sistema de gestão estudantil
|