关于java信息添加系统代码的信息

用java编写学生信息管理系统

仅仅给你个参考

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、虚拟空间、营销软件、网站建设、公安网站维护、网站推广。

//Java Group Project_StudentManagement源码

//NetBeans IDE 6.5 环境

package studentmanager;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.util.*;

class Student implements java.io.Serializable{

String number,name,specialty,grade,borth,sex;

public Student(){};

public void setNumber(String number)

public String getNumber()

public void setName(String name)

public String getName()

public void setSex(String sex)

public String getSex()

public void setSpecialty(String specialty)

public String getSpecialty()

public void setGrade(String grade)

public String getGrade()

public void setBorth(String borth)

public String getBorth()

}

public class StudentManager extends JFrame{

JLabel lb=new JLabel("录入请先输入记录,查询、删除请先输入学号,修改是对查询" +

"内容改后的保存!");

JTextField 学号,姓名,专业,年级,出生;

JRadioButton 男,女;

ButtonGroup group=null;

JButton 录入,查询,删除,修改,显示;

JPanel p1,p2,p3,p4,p5,p6,pv,ph;

Student 学生=null;

Hashtable 学生散列表=null;

File file=null;

FileInputStream inOne=null;

ObjectInputStream inTwo=null;

FileOutputStream outOne=null;

ObjectOutputStream outTwo=null;

public StudentManager(){

super("学生基本信息管理系统");

学号=new JTextField(10);

姓名=new JTextField(10);

专业=new JTextField(10);

年级=new JTextField(10);

出生=new JTextField(10);

group=new ButtonGroup();

男=new JRadioButton("男",true);

女=new JRadioButton("女",false);

group.add(男);

group.add(女);

录入=new JButton("录入");

查询=new JButton("查询");

删除=new JButton("删除");

修改=new JButton("修改");

显示=new JButton("显示");

录入.addActionListener(new InputAct());

查询.addActionListener(new InquestAct());

修改.addActionListener(new ModifyAct());

删除.addActionListener(new DeleteAct());

显示.addActionListener(new ShowAct());

修改.setEnabled(false);

p1=new JPanel();

p1.add(new JLabel("学号:",JLabel.CENTER));

p1.add(学号);

p2=new JPanel();

p2.add(new JLabel("姓名:",JLabel.CENTER));

p2.add(姓名);

p3=new JPanel();

p3.add(new JLabel("性别:",JLabel.CENTER));

p3.add(男);

p3.add(女);

p4=new JPanel();

p4.add(new JLabel("专业:",JLabel.CENTER));

p4.add(专业);

p5=new JPanel();

p5.add(new JLabel("年级:",JLabel.CENTER));

p5.add(年级);

p6=new JPanel();

p6.add(new JLabel("出生:",JLabel.CENTER));

p6.add(出生);

pv=new JPanel();

pv.setLayout(new GridLayout(6,1));

pv.add(p1);

pv.add(p2);

pv.add(p3);

pv.add(p4);

pv.add(p5);

pv.add(p6);

ph=new JPanel();

ph.add(录入);

ph.add(查询);

ph.add(修改);

ph.add(删除);

ph.add(显示);

file=new File("学生信息.txt");

学生散列表=new Hashtable();

if(!file.exists()){

try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out);

objectOut.writeObject(学生散列表);

objectOut.close();

out.close();

}

catch(IOException e){}

}

Container con=getContentPane();

con.setLayout(new BorderLayout());

con.add(lb, BorderLayout.NORTH);

con.add(pv, BorderLayout.CENTER);

con.add(ph, BorderLayout.SOUTH);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setBounds(100,100,600,300);

setVisible(true);

}

public static void main(String[] args)

class InputAct implements ActionListener{

public void actionPerformed(ActionEvent e){

修改.setEnabled(false);

String number="";

number=学号.getText();

if(number.length()0){

try{

inOne=new FileInputStream(file);

inTwo=new ObjectInputStream(inOne);

学生散列表=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exception ee)

if(学生散列表.containsKey(number)){

String warning="该生信息已存在,请到修改页面修改!";

JOptionPane.showMessageDialog(null,warning,"警告",

JOptionPane.WARNING_MESSAGE);

}//end if1

else{

String m="该生信息将被录入!";

int ok=JOptionPane.showConfirmDialog(null,m,"确认",

JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

String name=姓名.getText();

String specialty=专业.getText();

String grade=年级.getText();

String borth=出生.getText();

String sex=null;

if(男.isSelected())

else

学生=new Student();

学生.setNumber(number);

学生.setName(name);

学生.setSpecialty(specialty);

学生.setGrade(grade);

学生.setBorth(borth);

学生.setSex(sex);

try{

outOne=new FileOutputStream(file);

outTwo=new ObjectOutputStream(outOne);

学生散列表.put(number,学生);

outTwo.writeObject(学生散列表);

outTwo.close();

outOne.close();

}

catch(Exception ee)

学号.setText(null);

姓名.setText(null);

专业.setText(null);

年级.setText(null);

出生.setText(null);

}

}//end else1

}//end if0

else{

String warning="必须输入学号!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}//end else0

}//end actionPerformed

}//end class

class InquestAct implements ActionListener{

public void actionPerformed(ActionEvent e){

String number="";

number=学号.getText();

if(number.length()0){

try{

inOne=new FileInputStream(file);

inTwo=new ObjectInputStream(inOne);

学生散列表=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exception ee)

if(学生散列表.containsKey(number)){

修改.setEnabled(true);

Student stu=(Student)学生散列表.get(number);

姓名.setText(stu.getName());

专业.setText(stu.getSpecialty());

年级.setText(stu.getGrade());

出生.setText(stu.getBorth());

if(stu.getSex().equals("男"))

else

}

else{

修改.setEnabled(false);

String warning="该学号不存在!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

else{

修改.setEnabled(false);

String warning="必须输入学号!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

}

class ModifyAct implements ActionListener{

public void actionPerformed(ActionEvent e){

String number=学号.getText();

String name=姓名.getText();

String specialty=专业.getText();

String grade=年级.getText();

String borth=出生.getText();

String sex=null;

if(男.isSelected())

else

Student 学生=new Student();

学生.setNumber(number);

学生.setName(name);

学生.setSpecialty(specialty);

学生.setGrade(grade);

学生.setBorth(borth);

学生.setSex(sex);

try{

outOne=new FileOutputStream(file);

outTwo=new ObjectOutputStream(outOne);

学生散列表.put(number, 学生);

outTwo.writeObject(学生散列表);

outTwo.close();

outOne.close();

学号.setText(null);

姓名.setText(null);

专业.setText(null);

年级.setText(null);

出生.setText(null);

}

catch(Exception ee){

System.out.println("录入修改出现异常!");

修改.setEnabled(false);

}

}

}

class DeleteAct implements ActionListener{

public void actionPerformed(ActionEvent e){

修改.setEnabled(false);

String number=学号.getText();

if(number.length()0){

try{

inOne=new FileInputStream(file);

inTwo=new ObjectInputStream(inOne);

学生散列表=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exception ee){}

if(学生散列表.containsKey(number)){

Student stu=(Student)学生散列表.get(number);

姓名.setText(stu.getName());

专业.setText(stu.getSpecialty());

年级.setText(stu.getGrade());

出生.setText(stu.getBorth());

if(stu.getSex().equals("男"))

else

}

String m="确定要删除该学生的记录吗?";

int ok=JOptionPane.showConfirmDialog(null,m,"确认",

JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

if(ok==JOptionPane.YES_OPTION){

学生散列表.remove(number);

try{

outOne=new FileOutputStream(file);

outTwo=new ObjectOutputStream(outOne);

outTwo.writeObject(学生散列表);

outTwo.close();

outOne.close();

学号.setText(null);

姓名.setText(null);

专业.setText(null);

年级.setText(null);

出生.setText(null);

}

catch(Exception ee)

}

else if(ok==JOptionPane.NO_OPTION){

学号.setText(null);

姓名.setText(null);

专业.setText(null);

年级.setText(null);

出生.setText(null);

}

else{

String warning="该学号不存在!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

else{

String warning="必须输入学号!";

JOptionPane.showMessageDialog(null,warning,

"警告",JOptionPane.WARNING_MESSAGE);

}

}

}

class ShowAct implements ActionListener{

public void actionPerformed(ActionEvent e){

new StudentShow(file);

}

}

class StudentShow extends JDialog{

Hashtable 学生散列表= null;

JTextArea 显示=null;

FileInputStream inOne=null;

ObjectInputStream inTwo=null;

File file=null;

public StudentShow(File file){

super(new JFrame(),"显示对话框");

this.file=file;

显示=new JTextArea(16,30);

try{

inOne=new FileInputStream(file);

inTwo=new ObjectInputStream(inOne);

学生散列表=(Hashtable)inTwo.readObject();

inOne.close();

inTwo.close();

}

catch(Exception ee){}

if(学生散列表.isEmpty())显示.append("目前还没有学生的信息记录!\n");

else{

显示.setText("学号 姓名 性别 专业 年级 出生\n");

for(Enumeration enm=学生散列表.elements();enm.hasMoreElements();){

Student stu=(Student)enm.nextElement();

String sex="";

if(stu.getSex().equals("男"))sex="男";

else sex="女";

String str=stu.getNumber()+","+stu.getName()+","+sex+","

+stu.getSpecialty()+","+stu.getGrade()+","+stu.getBorth()+"\n";

显示.append(str);

}

}

JScrollPane scroll=new JScrollPane(显示);

Container con=getContentPane();

con.add("Center",scroll);

con.validate();

setVisible(true);

setBounds(200,200,400,300);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e)

}

);

}

}

}

利用swing设计一个班级学生信息管理系统,一道JAVA题 求代码,不要废话

public class RandomUtils {

public static String randomId(){

Random random = new Random();

StringBuilder sb = new StringBuilder();

for (int i = 0; i  6; i++) {

sb.append(random.nextInt(10));

}

return sb.toString();

}

public static int randomIntId(){

Random random = new Random();

StringBuilder sb = new StringBuilder();

for (int i = 0; i  6; i++) {

sb.append(random.nextInt(10));

}

return Integer.parseInt(sb.toString());

}

public static String randomName(){

String[] name1 = {"赵","钱","孙","李","周","吴","郑","王","张","刘"};

String[] name2 = {"一","二","三","四","五","六","七","八","九","十"};

Random random = new Random();

StringBuilder sb = new StringBuilder();

sb.append(name1[random.nextInt(10)]);

sb.append(name2[random.nextInt(10)]);

sb.append(name2[random.nextInt(10)]);

return sb.toString();

}

public static String randomSex(){

Random random = new Random();

return random.nextInt(4)/2==0?"男":"女";

}

public static int randomAge(int min, int max){

Random random = new Random();

return random.nextInt(min) + max-min;

}

public static int randomScore(){

Random random = new Random();

return (int)(random.nextDouble()*100%100);

}

public static String randomAddress(){

String[] address1 = {"商业","红叶","安康","河南","长海","黄河","桐柏","科学","瑞达","花园"};

String[] address2 = {"东","南","西","北","中"};

String[] address3 = {"街","路","大道","巷"};

Random random = new Random();

StringBuilder sb = new StringBuilder();

sb.append(address1[random.nextInt(10)]);

sb.append(address2[random.nextInt(5)]);

sb.append(address3[random.nextInt(4)]);

sb.append(random.nextInt(1000)+1);

sb.append("号");

return sb.toString();

}

}

import javax.swing.*;

import javax.swing.event.TreeSelectionEvent;

import javax.swing.event.TreeSelectionListener;

import javax.swing.table.DefaultTableModel;

import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.*;

import java.util.*;

import java.util.List;

public class StudentManage extends JFrame{

public final static String[] CH_NUM = {"一","二","三","四","五","六","七","八","九","十"};

public final static String ROOT = "班级管理";

public final static int GRADE_NUM = 3;

public final static int CLASS_NUM = 3;

private MapString, ListStudent classes;

public StudentManage() {

setTitle("学生管理系统");

setSize(300, 300);

setLayout(new BorderLayout());

if(classes == null) classes = new HashMap();

DefaultMutableTreeNode top = new DefaultMutableTreeNode(ROOT);

DefaultMutableTreeNode[] gradeNodes = new DefaultMutableTreeNode[GRADE_NUM];

for (int i = 0; i  GRADE_NUM; i++) {

gradeNodes[i] = new DefaultMutableTreeNode(CH_NUM[i] + "年级");

for (int j = 0; j  CLASS_NUM; j++) {

gradeNodes[i].add(new DefaultMutableTreeNode(CH_NUM[j] + "班"));

}

top.add(gradeNodes[i]);

}

final JTree tree = new JTree(top);

String title[] = {"ID","姓名","性别","年龄","地址"};

final DefaultTableModel model = new DefaultTableModel(title, 0);

JTable table=new JTable(model);

tree.addTreeSelectionListener(new TreeSelectionListener() {

@Override

public void valueChanged(TreeSelectionEvent e) {

DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree .getLastSelectedPathComponent();

if (node == null) return;

Object object = node.getUserObject();

if (node.isLeaf()) {

ListStudent stdList = classes.get(getFullPath(node));

Object[][] data = new Object[stdList.size()][5];

for (int i = 0; i  stdList.size(); i++) {

data[i][0] = stdList.get(i).getId();

data[i][1] = stdList.get(i).getName();

data[i][2] = stdList.get(i).getSex();

data[i][3] = stdList.get(i).getAge();

data[i][4] = stdList.get(i).getAddress();

}

while(model.getRowCount()0){

model.removeRow(model.getRowCount()-1);

}

for (int i = 0; i  stdList.size(); i++) {

model.addRow(data[i]);

}

model.fireTableDataChanged();

}

}

});

add(tree, BorderLayout.WEST);

add(new JScrollPane(table), BorderLayout.CENTER);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private String getFullPath(DefaultMutableTreeNode defaultMutableTreeNode){

StringBuilder sb = new StringBuilder();

Object[] objs = defaultMutableTreeNode.getUserObjectPath();

for (int i = 0; i  objs.length; i++) {

sb.append(objs[i]);

}

return sb.toString().replace(ROOT,"");

}

public void init(){

for (int i = 0; i  GRADE_NUM; i++) {

for (int j = 0; j  CLASS_NUM; j++) {

int n = new Random().nextInt(30)+1;

ListStudent stdList = new ArrayList(n);

for (int k = 0; k  n; k++) {

stdList.add(new Student(RandomUtils.randomIntId(),RandomUtils.randomName(),RandomUtils.randomSex(),

RandomUtils.randomAge(6,12),RandomUtils.randomAddress()));

}

classes.put(CH_NUM[i] + "年级"+ CH_NUM[j] +"班", stdList);

}

}

}

public static void main(String[] args) {

StudentManage studentManage = new StudentManage();

studentManage.init();

}

}

class Student {

private int id;

private String name;

private String sex;

private int age;

private String address;

public Student(int id, String name, String sex, int age, String address) {

this.id = id;

this.name = name;

this.sex = sex;

this.age = age;

this.address = address;

}

public Student() {

}

public int getId() {

return id;

}

public String getName() {

return name;

}

public String getSex() {

return sex;

}

public int getAge() {

return age;

}

public String getAddress() {

return address;

}

@Override

public String toString() {

return "Student{" +

"id=" + id +

", name='" + name + '\'' +

", sex='" + sex + '\'' +

", age=" + age +

", address='" + address + '\'' +

'}';

}

}

急求java学生信息管理系统源代码,带有连接数据库的,万分感谢

import java.awt.BorderLayout;

import java.awt.CardLayout;

import java.awt.Container;

import java.awt.Font;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JPanel;

import javax.swing.JToolBar;

import javax.swing.SwingConstants;

public class MainFrame extends JFrame implements ActionListener{

InsertPanel ip = null;

SelectPanel sp = null;

JPanel pframe;

JButton jb1,jb2,jb3;

JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;

CardLayout clayout;

public MainFrame(String s){

super(s);

JMenuBar mb = new JMenuBar();

this.setJMenuBar(mb);

JMenu m1 = new JMenu("系统");

JMenu m2 = new JMenu("基本信息");

JMenu m3 = new JMenu("成绩");

JMenu m4 = new JMenu("奖惩");

mb.add(m1);

mb.add(m2);

mb.add(m3);

mb.add(m4);

jm11 = new JMenuItem("退出系统");

jm21 = new JMenuItem("输入");

jm22 = new JMenuItem("查询");

jm23 = new JMenuItem("更改");

jm31 = new JMenuItem("输入成绩");

jm32 = new JMenuItem("查询成绩");

jm41 = new JMenuItem("奖励");

jm42 = new JMenuItem("处分");

m1.add(jm11);

m2.add(jm21);

m2.add(jm22);

m2.add(jm23);

m3.add(jm31);

m3.add(jm32);

m4.add(jm41);

m4.add(jm42);

Icon i1 = new ImageIcon();

Icon i2 = new ImageIcon();

Icon i3 = new ImageIcon();

jb1 = new JButton(i1);

jb1.setToolTipText("输入");

jb2 = new JButton(i2);

jb2.setToolTipText("查询");

jb3 = new JButton(i3);

jb3.setToolTipText("退出");

JToolBar tb = new JToolBar("系统工具");

tb.add(jb1);

tb.add(jb2);

tb.add(jb3);

add(tb,BorderLayout.NORTH);

jm11.addActionListener(this);

jm21.addActionListener(this);

jm22.addActionListener(this);

jb1.addActionListener(this);

jb2.addActionListener(this);

jb3.addActionListener(this);

clayout = new CardLayout();

pframe = new JPanel(clayout);

add(pframe);

JPanel mainp = new JPanel(new BorderLayout());

JLabel mainl = new JLabel("学生信息管理平台",SwingConstants.CENTER);

mainl.setFont(new Font("serif",Font.BOLD,30));

mainp.add(mainl);

pframe.add(mainp,"main");

clayout.show(pframe, "main");

}

public void actionPerformed(ActionEvent e){

if(e.getSource() == jm21 || e.getSource() == jb1){

if(ip == null){

ip= new InsertPanel();

pframe.add(ip,"insert");

}

clayout.show(pframe, "insert");

this.setTitle("输入学生信息");

}

else if(e.getSource() == jm22 || e.getSource() == jb2){

if(sp == null){

sp= new SelectPanel();

pframe.add(sp,"select");

}

clayout.show(pframe, "select");

this.setTitle("查询学生信息");

}

else if(e.getSource() == jm11 || e.getSource() == jb3){

System.exit(0);

}

}

}

第二个:

import javax.swing.JFrame;

public class MainTest {

public static void main(String [] args){

MainFrame f = new MainFrame("学生信息管理平台");

f.setSize(400,300);

f.setLocation(350,250);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

}

}

第二个:

import java.sql.Connection;

import java.sql.DriverManager;

public class MySQLConnection {

static Connection getCon(){

Connection con = null;

try{

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

con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");

}

catch(Exception e){

System.out.println("建立数据库连接遇到异常!");

}

return con;

}

}

第四个:

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

public class SelectPanel extends JPanel implements ActionListener{

JButton jb;

JTextField jt;

JTextField jt1,jt2,jt3,jt4;

public SelectPanel(){

JLabel jl = new JLabel("请输入学号:",SwingConstants.CENTER);

jt = new JTextField();

jb = new JButton("确定");

JPanel jp1 = new JPanel(new GridLayout(1,3));

jp1.add(jl);

jp1.add(jt);

jp1.add(jb);

JLabel j1,j2,j3,j4;

j1 = new JLabel("学号:",SwingConstants.CENTER);

j2 = new JLabel("姓名:",SwingConstants.CENTER);

j3 = new JLabel("性别:",SwingConstants.CENTER);

j4 = new JLabel("年龄:",SwingConstants.CENTER);

jt1 = new JTextField(6);

jt1.setEditable(false);

jt2 = new JTextField(6);

jt2.setEditable(false);

jt3 = new JTextField(6);

jt3.setEditable(false);

jt4 = new JTextField(6);

jt4.setEditable(false);

JPanel jp2 = new JPanel(new BorderLayout());

JPanel jp3 = new JPanel(new GridLayout(4,2));

jp2.add(new JLabel(""),BorderLayout.NORTH);

jp3.add(j1);

jp3.add(jt1);

jp3.add(j2);

jp3.add(jt2);

jp3.add(j3);

jp3.add(jt3);

jp3.add(j4);

jp3.add(jt4);

jp2.add(jp3);

this.setLayout(new BorderLayout());

add(jp1,BorderLayout.NORTH);

add(jp2);

jb.addActionListener(this);

}

public void actionPerformed(ActionEvent e){

if(e.getSource() == jb){

String stuNo = jt.getText().trim();

Student s = new Student();

boolean b = true;

try{

b = s.selectByStuNo(stuNo);

}

catch(Exception ex){

System.out.println("查询学生信息遇到异常!");

}

if(b){

jt1.setText(s.getStuNo());

jt2.setText(s.getName());

jt3.setText(s.getGender());

int a = s.getAge();

Integer i = new Integer(a);

jt4.setText(i.toString());

}

else{

JOptionPane.showMessageDialog(null, "无此学生!");

}

}

}

}

第五个:

import javax.swing.JFrame;

public class SelectTest {

public static void main(String [] args){

JFrame f = new JFrame("查询学生信息");

SelectPanel p = new SelectPanel();

f.add(p);

f.setSize(400,300);

f.setLocation(300,250);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

}

}

第六个:

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;

public class Student {

String stuNo;

String name;

String gender;

int age;

public Student(){}

public Student(String stuNo,String name,String gender, int age){

this.stuNo = stuNo;

this.name = name;

this.gender = gender;

this.age = age;

}

public String getStuNo(){

return stuNo;

}

public void setStuNo(String stuNo){

this.stuNo = stuNo;

}

public String getName(){

return name;

}

public void setName(String name){

this.name = name;

}

public String getGender(){

return gender;

}

public void setGender(String gender){

this.gender = gender;

}

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 != null rs.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信息添加系统代码的信息
转载来源:http://azwzsj.com/article/hiejio.html