JAVA查看学生信息代码 学生信息查询系统java( 三 )


public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != nullrs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,JAVA查看学生信息代码我没时间弄JAVA查看学生信息代码了!初学得多动手哦
用JAVA list集合语句增删改查全部学生信息 。1、首先在电脑上启动数据库,在数据库中创建表,下面给出具体的SQL语句 。
2、然后打开eclipse 创建新项目 JDBCTest , 需要导入相关的jar包并构建路径,如图 。
3、接着创建entity实体层如图对应表中的数据 。
4、创建数据连接层conn 用于MySQL数据库的连接代码如图 如图 。
5、创建dao层持久层,在里面编写数据库表的增删改查的具体操作 。
6、最后编写测试类 Test代码如图,就完成了 。
java中实现对学生信息的输入、输出、修改、查找 , 该如何做?Java 代码如下:import java.util.ArrayList;
import java.util.Scanner;public class student{
private int number;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public student(){}
public student(int number, String name) {
this.number = number;
this.name = name;
}
public student writeInfo(){
student st = new student();
Scanner in = new Scanner(System.in);
System.out.println("请输入学生的学号:");
number = in.nextInt();
st.setNumber(number);
System.out.println("请输入学生的姓名:");
String name = in.next();
st.setName(name);
return st;
}
public void readInfo(ArrayList list){
for(int i=0;i=list.size()-1;i++){
student st = new student();
st = (student) list.get(i);
System.out.println("第"+(i+1)+"位学生的学号:" + st.getNumber());
System.out.println("第"+(i+1)+"位学生的姓名:" + st.getName());
}
}
public static void main(String[]args){ArrayListstudent list = new ArrayListstudent();
student st = new student();
Scanner in = new Scanner(System.in);
while(true){
System.out.println("1、输入学生信息");
System.out.println("2、输出学生信息");
System.out.println("请选择:");
int option = in.nextInt();
switch (option) {
case 1:
list.add(st.writeInfo());
break;
case 2:

推荐阅读