|
|

Questo post è stato modificato l'ultima volta da Delver_Si il 20-11-2014 alle 21:21
[mw_shl_code=sql,true]usa master Vai if exists (seleziona * da sys.databases dove nome = 'scuola') Scuola del database di abbandonamento Vai Crea scuola di database Vai Usa la scuola Vai crea tavolo studente
( stu_id varchar(10) numero di ,-- chiave primaria stu_name varchar(20) non nullo,-- nome stu_addr Varchar (100) ,-- indirizzo stu_spec Varchar (50) ,-- professionista stu_dorm Varchar (50) — Dormitorio
) Vai inserire nei valori degli studenti ('100001', 'Zhang San', 'Wuhan Xu Dong', 'Ingegneria dell'Informazione', '101') inserisci nei valori degli studenti ('100002', 'Li Si', 'Wuhan Xu Dong', 'Ingegneria dell'Informazione', '102')
seleziona * da studente
--elimina da studente dove stu_id = '100001'
--update student set stu_name = 'Li Si', stu_addr = 'Zhang San', stu_spec= 'Software Testing', stu_dorm = '1001' dove stu_id = '100001'[/mw_shl_code]
[mw_shl_code=java,true]pacchetto online.school.test;
import java.util.ArrayList; importa java.util.List; importare online.school.domain.Student; importazione online.school.service.StudentService;
classe pubblica StudentTest {
Public static void main(String[] args) { nuovo StudentTest().getAllStudent(); } public int addStudent() { Studente studente = nuovo studente ("3", "Wang Wu", "Xiaogan", "Test Software", "103"); return new StudentService().addStudent(student); }
public int delStudent() { Stringa stuId="3"; return new StudentService().delStudent(stuId); }
public void findStudent() { Stringa stuId="3"; Studente studente =nuovo StudentService().findStudent(stuId); System.out.println(student.toString()); }
public List<Student> getAllStudent() { ArrayList al = (ArrayList) nuovo StudentService().getAllStudent(); for(int i =0; i<al.size(); i++){ Object[] obj =(Object[]) al.get(i); for(int j=0; j<5; j++){ System.out.print(obj[j] + " "); } System.out.println(); } Ritorna Al; }
public int updateStudent() {
Studente studente = nuovo studente ("3", "Wang Wu", "Yingcheng", "Ingegneria Civile", "103"); nuovo StudentService().updateStudent(student); ritorno 0;
}
} [/mw_shl_code]
[mw_shl_code=java,true]pacchetto online.school.domain;
classe pubblica Studente {
il soldato String stu_id; numero soldato semplice String stu_name; Nome soldato semplice String stu_addr; - Indirizzo soldato semplice String stu_spec; Professionistico String stu_dorm; Dormitorio Public String getStu_id() { ritorno stu_id; } public void setStu_id(String stuId) { stu_id = stuId; } Public String getStu_name() { ritorno stu_name; } public void setStu_name(Stringa stuName) { stu_name = stuName; } Public String getStu_addr() { ritorno stu_addr; } public void setStu_addr(String stuAddr) { stu_addr = stuAddr; } Public String getStu_spec() { ritorno stu_spec; } public void setStu_spec(String stuSpec) { stu_spec = stuSpec; } Public String getStu_dorm() { ritorno stu_dorm; } public void setStu_dorm(String stuDorm) { stu_dorm = stuDormitorio; }
Studente pubblico() { 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 = stuDormitorio; } @Override public Stringa a Stringa() { ritorna "Studente [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]pacchetto online.school.service;
importa java.util.List;
import online.school.dao.StudentDao; importare online.school.domain.Student; importare online.school.utils.SqlHelp;
la classe pubblica StudentService implementa IStudentService{
@Override public int addStudent(Student studente) {
String sql = "inserire nei valori studenti(?,?,?,?,?)"; 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 = "elimina da studente dove stu_id = ?"; return new StudentDao().delStudent(sql, stuId); }
@Override pubblico Student findStudent(String stuId) { String sql = "seleziona * da studente dove stu_id = ?"; return new StudentDao().findStudent(sql, stuId); }
@Override public List<Student> getAllStudent() { String sql = "seleziona * da studente"; return new StudentDao().getAllStudent(sql); }
@Override public int updateStudent(Student studente) { String sql = "update student set stu_name = ?,stu_addr = ?, stu_spec= ?,stu_dorm = ? dove 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]pacchetto online.school.dao;
import java.util.ArrayList; importa java.util.List; importare online.school.domain.Student; importare online.school.utils.SqlHelp;
la classe pubblica 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 Studente pubblico trovandoStudente (String sql, String... args) { ArrayList al = new SqlHelp().executeQuery(sql, args); Oggetto[] obj =(Oggetto[]) al.get(0); Studente studente = nuovo Studente(); student.setStu_id((Corda) obj[0]); student.setStu_name((Corda) obj[1]); student.setStu_addr((Corda) obj[2]); student.setStu_spec((Stringa) obj[3]); student.setStu_dorm((Corda) obj[4]); studente di ritorno;
}
@Override public List<Student> getAllStudent(String sql) {
ArrayList al = new SqlHelp().executeQuery(sql); Ritorna Al; }
@Override public int updateStudent(String sql, String... args) {
return new SqlHelp().executeUpdate(sql, args);
}
} [/mw_shl_code]
|
Precedente:Recentemente sto facendo un progetto in una libreria online, che è una funzione di registrazione che è stata realizzata negli ultimi giorniProssimo:Versione C# del sistema di gestione degli studenti
|