内容发布更新时间 : 2024/11/9 3:48:58星期一 下面是文章的全部内容请认真阅读。
[ssfby] [char](10) NULL, [sbyrq] [datetime] NULL,
CONSTRAINT [PK_student] PRIMARY KEY CLUSTERED ( [sno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
SET ANSI_PADDING OFF GO
/****** 对象: Table [dbo].[rewardpunish] 脚本日期: 05/07/2014 11:07:39 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON GO
CREATE TABLE [dbo].[rewardpunish]( [sno] [int] NOT NULL, [rtype] [char](10) NULL, [rdate] [datetime] NULL ) ON [PRIMARY] GO
SET ANSI_PADDING OFF GO
/****** 对象: Table [dbo].[class] 脚本日期: 05/07/2014 11:07:39 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON GO
CREATE TABLE [dbo].[class]( [bh] [int] NOT NULL, [yx] [char](20) NULL, [mc] [char](20) NULL, [rs] [int] NULL,
CONSTRAINT [PK_class] PRIMARY KEY CLUSTERED ( [bh] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
GO
SET ANSI_PADDING OFF GO
/****** 对象: Table [dbo].[teacher] 脚本日期: 05/07/2014 11:07:39 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON GO
CREATE TABLE [dbo].[teacher]( [tno] [int] NOT NULL, [tname] [char](10) NULL, [tsex] [char](2) NULL, [tprofess] [char](10) NULL, [ttel] [char](10) NULL,
CONSTRAINT [PK_teacher] PRIMARY KEY CLUSTERED ( [tno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
SET ANSI_PADDING OFF GO
/****** 对象: Table [dbo].[score] 脚本日期: 05/07/2014 11:07:39 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
CREATE TABLE [dbo].[score]( [sno] [int] NOT NULL, [cno] [int] NOT NULL, [score] [smallint] NULL,
CONSTRAINT [PK_score] PRIMARY KEY CLUSTERED ( [sno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
/****** 对象: Table [dbo].[course] 脚本日期: 05/07/2014 11:07:39 ******/ SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON GO
CREATE TABLE [dbo].[course]( [cno] [int] NOT NULL, [cname] [char](20) NULL, [cyear] [char](10) NULL, [cterm] [char](10) NULL ) ON [PRIMARY] GO
SET ANSI_PADDING OFF GO
3.2 业务逻辑层类及代码 (1)数据查询 语句格式:
SELECT [ALL/DISTINCT] <目标列名表达式> [别名] [,<目标列名表达式> [别名]]… FROM <表名或视图名> [别名][, <表名或视图名> [别名]]… [WHERE<条件表达式>]
[GROUP BY<列名1>[HAVING<条件表达式>]] [ORDER BY <列名2>[ASC/DESC]];
——查询查询所有选修了1001号课程的学生姓名 SELECT sname FROM student WHERE EXISTS
(SELECT * FROM SC WHERE Sno=student.sno AND cno=’1001’)
(2)数据删除 语句格式: DELETE FROM<表明> [WHERE<条件>];
——删除学号为2011021的学生记录 DELECT FROM student WHERE sno=’2011021’ (3)数据修改 语句格式:
UPDATE<表名>
SET <列名>=<表达式>[, <列名>=<表达式>]… [WHERE<条件>];
——将所有学生的年龄加1 UPDATE student SET sage=sage+1 (4)插入数据 语句格式: INSERT
INTO<表名>[(<属性列1>[<属性列2>…]) VALUES(<常量1>[,常量2]….); ——在学生表中插入 Insert into
student(sno,sname,ssex,sage,smz,sjg,szzmm,sdepart,smajor,sgrade,sclass,srxcj,ssfby,sbyrq)values(‘2011022’,’王强’,’男’ ‘20’,’汉族’,’云南’ ,‘团员’,’数学与应用数学’,’2011’ ‘2’,’412’,’是’,’2013/6/7’) ——在课程表中插入
Insert into course(cno,cname,cyear,cterm)values(‘1022’,’JAVA’,2013’ ‘1’) ——在成绩表中插入
Insert into score(cno,cno,score)values(‘2011022’,’1022’,67’ )
3.3表示层的实现 (1)登陆
import java.util.Scanner; import java.sql.*;
public class Student { static boolean flag; //标记是否为管理员 static int i =0; //限制密码输入次数 static String present_name; //记录当前用户 public static void log_in(String name,String pwd) throws Exception//用户登录验证 { String DBDrive = \ String connectionStr = \ Connection con = null; Statement stmt = null; ResultSet rs = null;
Class.forName(DBDrive); con = DriverManager.getConnection(connectionStr,\ stmt = con.createStatement(); rs = stmt.executeQuery(\* From users where username= '\and password= '\ if(rs.next()) { System.out.println(\登录成功!\ }
(2)主界面
public void show_DataBase_Information()//显示数据库中学生的个人基本信息 {
String Information; if(ConnectDataBase()) { try {
str=\ ResultSet s1=st1.executeQuery(str); int i=0; while(s1.next()) {
if(i>MaxNum) break;
Information=s1.getString(1)+\ +\ Student_Information[i]=Information; i++; }
NowInformationNum=i; Close_database(); }catch(SQLException e) {
System.out.println(e.toString()); } }