搜档网
当前位置:搜档网 › 复习资料编程题练习

复习资料编程题练习

复习资料编程题练习
复习资料编程题练习

表stuScore

CREATE TABLE stuScore(

stuID int(4) NOT NULL PRIMARY KEY AUTO_INCREMENT,

stuName varchar(30) NOT NULL,

courceName varchar(50) NOT NULL,

courceScore float(6,2) NOT NULL

)

delete from stuScore where courceScore<20

update stuScore set stuName='李明湖' where stuID=7

select * from stuScore where stuName like '%通%'

insert into stuScore (STUNAME,courceName,courceScore) values (‘SONGSHUANGSHUANG’,’种子科学',36)

表stuInfo

其中字段1:名称为:stuID,类型为:int,数据长度为4,是主键且自动增长;

其他字段如图所示

CREATE TABLE stuInfo (

stuID int(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, stuName varchar(30) NOT NULL,

stuAge int(2) NULL

delete from stuInfo where stuAge<22

update stuInfo set stuName='李明湖' where stuID=7

select * from stuInfo where stuName like '%明%'

insert into stuInfo (stuID ,stuName, stuAge) values (9,'离散数学',36)

表courceInfo

CREATE TABLE courceInfo (

couID int(4) NOT NULL PRIMARY KEY AUTO_INCREMENT, couName varchar(30) NOT NULL,

couHour int(3) NOT NULL

)

delete from courceInfo where couHour<500

update courceInfo set couName='种子科学' where stuid=4

select * from courceInfo where couName like '%种%'

insert into courceInfo (couName,couHour) values ('离散数学',36)

1 完成上述三个表的创建,数据的增删查改功能

2 完成以上注册页面表单的编写。

注册信息:

姓名:

性别:

职业:

爱好:旅游看书

游戏


注册信息:

用户名:

密码:

兴趣:学习阅读

运动
性别:


3编写注册页面(reg.jsp)并将数据以post方式提交到receive.jsp,注册页面中至少包含有姓名,性别,职业,爱好等信息。在接收页面将注册内容显示出来。

在login.jsp页面,

用户名:

密码:

职业:

爱好:


在loginCheck.jsp页面

<%

request.setCharacterEncoding("UTF-8");

String userName = request.getParameter("userName");

String password = request.getParameter("passWord");

if(userName.equals("admin") && password.equals("admin")){

System.out.println("登录成功!");

}

else{

System.out.println("登录系统失败!");

}

%>

4 练习类,接口,类的继承,封装,接口的实现,包

package https://www.sodocs.net/doc/249902782.html,.tjau.as;

public interface IPerson {

public void Eat();

public void Drink();

public void Sleep();

}

package https://www.sodocs.net/doc/249902782.html,.tjau.as;

public class Person {

private String name; //姓名

private int age; //年龄

public void setName(String name){

https://www.sodocs.net/doc/249902782.html,=name;

public String getName(){

return https://www.sodocs.net/doc/249902782.html,;

}

public void setAge(int age){

this.age = age;

}

public void getAge(){

return this.age ;

}

public void print(){//打印年龄

System.out.println(name+"年龄是:"+ getAge());

}

}

编写继承Person类,实现IPerson接口的Student类,创建到https://www.sodocs.net/doc/249902782.html,.tjau.as包中,要求在Student 类中加入“score”(分数)成员变量,创建加入构造方法包含姓名,年龄,分数信息,加入show方法在控制台输出学生的姓名和分数。

package https://www.sodocs.net/doc/249902782.html,.tjau.as;

import https://www.sodocs.net/doc/249902782.html,.tjau.as.*;

public class Student extends Person implements IPerson {

private int score; //分数

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

public void show(){

System.out.println("学生"+ getName()+"的分数为:"+score);

}

public void Eat(){

System.out.println("我爱吃西瓜!");

}

public void Drink(){

System.out.println("我爱喝汽水!");

}

public void Sleep(){

System.out.println("wukai上课不能睡觉!");

}

}

5 从控制台输入用户名和密码,如果用户名和密码都是admin,则提示“系统登录成功!”,否则继续输入用户名和密码,如果3次都没有成功,则提示“你3次登录系统失败,请稍后

import java.util.*;

public class Login {

public static void main(String[] args){

String userName;

String userPassword;

int i;

for(i=1;i<=3;i++){

Scanner input = new Scanner(System.in);

System.out.println("请输入用户名:");

userName = input.next();

System.out.println("请输入密码:");

userPassword = input.next();

if(userName.equals("admin")&&userPassword.equals("admin")){

System.out.println("系统登录成功!");

return;//终止main方法后面的代码执行

}

else

{

System.out.println("登录系统失败!");

}

if(i>3)

{ System.out.println("你3次登录系统失败,请稍后再登录!");}

}

}

6 数据库名称为:student,访问数据库的用户名为:root,密码为:222,编写脚本代码完成对表CourceInfo的数据

(1)插入操作,假设课程名称“couName”为“应用软件开发”,课时“couHour”为“36”。(2)删除刚刚插入的数据。

(3)更改课程名称“couName”为“应用程序开发基础”。

(4)查询所有数据并将所有内容输出到控制台中。

Class.forName("com.mysql.jdbc.Driver");

Connection

conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "ROOT", "222");

Statement stmt=conn.createStatement();

String sql =" insert into courceInfo (couName,couHour) values ('应用软件开发',36)";

// String sql =" delete from CourceInfo where couName='应用软件开发'";

// String sql =" update CourceInfo set couName = ‘应用程序开发基础’, set couHour =36 where id = 5";

//String sql = "select * from CourceInfo";

ResultSet rs = stmt.executeQuery(sql);

int result=stmt.executeUpdate(sql);

if(result > 0) {

System.out.println("修改数据成功!");

}

else{

System.out.println("修改数据失败!");

}

stmt.close();

conn.close();

/** while(rs.next()){

String couName = rs.getString("couName ");

int couHour = rs.getInt("couHour ");

System.out.println(课程名:"+ couName +"课时:"+ couHour );

}

stmt.close();

conn.close();

*/

相关主题