java增加和删除代码 java批量删除代码

基于java设计一个学生成绩管理系统,要求有界面,且有增加,查询,修改,删除,退出功能,代码如何写?

import java.awt.Color;

创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都网站设计、前锋网络推广、微信小程序开发、前锋网络营销、前锋企业策划、前锋品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供前锋建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

import java.awt.Font;

import java.awt.Frame;

import java.awt.Label;

import java.awt.TextField;

import java.awt.Window;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.sql.SQLException;

import javax.swing.JButton;

public class Stmessege {

Font font = new Font("楷体", Font.BOLD, 18);

private Frame m = new Frame("登陆成功界面");

protected Window f;

public Stmessege() {

m.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent evt) {

m.setVisible(false);

m.dispose();

System.exit(0);

}

});

m.setSize(460, 360);

m.setBackground(Color.green);

m.setLayout(null);

m.setLocationRelativeTo(null);

Label l0 = new Label("管理员信息");

Font font1 = new Font("楷体", Font.BOLD, 32);

l0.setForeground(Color.blue);

l0.setSize(180, 50);

l0.setLocation(150, 30);

l0.setFont(font1);

final Label l1 = new Label("姓名:");

l1.setSize(60, 20);

l1.setLocation(10, 100);

l1.setFont(font);

TextField tf1 = new TextField("黄朋");

tf1.setForeground(Color.blue);

tf1.setBackground(Color.white);

tf1.setSize(50, 20);

tf1.setLocation(70, 100);

final Label l2 = new Label("学号:");

l2.setSize(60, 20);

l2.setLocation(140, 100);

l2.setFont(font);

TextField tf2 = new TextField("111265");

tf2.setForeground(Color.blue);

tf2.setBackground(Color.white);

tf2.setSize(60, 20);

tf2.setLocation(190, 100);

final Label l3 = new Label("性别:");

l3.setSize(60, 20);

l3.setLocation(280, 100);

l3.setFont(font);

TextField tf3 = new TextField("男");

tf3.setForeground(Color.blue);

tf3.setBackground(Color.white);

tf3.setSize(40, 20);

tf3.setLocation(360, 100);

final Label l4 = new Label("班级:");

l4.setSize(60, 20);

l4.setLocation(10, 170);

l4.setFont(font);

TextField tf4 = new TextField("611231");

tf4.setForeground(Color.blue);

tf4.setBackground(Color.white);

tf4.setSize(60, 20);

tf4.setLocation(67, 170);

final Label l5 = new Label("系别:");

l5.setSize(60, 20);

l5.setLocation(140, 170);

l5.setFont(font);

TextField tf5 = new TextField("计算机工程系");

tf5.setForeground(Color.blue);

tf5.setBackground(Color.white);

tf5.setSize(80, 20);

tf5.setLocation(200, 170);

final Label l6 = new Label("成绩:");

l6.setSize(60, 20);

l6.setLocation(280, 170);

l6.setFont(font);

TextField tf6 = new TextField("95");

tf6.setForeground(Color.blue);

tf6.setBackground(Color.white);

tf6.setSize(40, 20);

tf6.setLocation(360, 170);

final Label l7 = new Label("专业:");

l7.setSize(60, 20);

l7.setLocation(10, 230);

l7.setFont(font);

TextField tf7 = new TextField("软件技术");

tf7.setForeground(Color.blue);

tf7.setBackground(Color.white);

tf7.setSize(60, 20);

tf7.setLocation(70, 230);

JButton btn1 = new JButton("添加");

btn1.setForeground(Color.blue);

btn1.setSize(80, 38);

btn1.setLocation(35, 300);

btn1.setFont(font);

btn1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new 插入();

m.setVisible(true);

}

});

JButton btn2 = new JButton("查询学生学籍信息");

btn2.setForeground(Color.blue);

btn2.setSize(200, 38);

btn2.setLocation(135, 300);

btn2.setFont(font);

btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Stmessege1 f;

try {

f = new Stmessege1();

f.Stmessege11();

m.setVisible(true);

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

});

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

btn3.setForeground(Color.blue);

btn3.setSize(80, 38);

btn3.setLocation(350, 300);

btn3.setFont(font);

btn3.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new 删除();

//f.setVisible(false);

m.setVisible(true);

}

});

JButton btn4 = new JButton("更新");

btn4.setForeground(Color.blue);

btn4.setSize(80, 38);

btn4.setLocation(200, 230);

btn4.setFont(font);

btn4.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new 更新();

m.setVisible(true);

}

});

m.add(l0);

m.add(l1);

m.add(tf1);

m.add(l2);

m.add(tf2);

m.add(l3);

m.add(tf3);

m.add(l4);

m.add(tf4);

m.add(l5);

m.add(tf5);

m.add(l6);

m.add(tf6);

m.add(l7);

m.add(tf7);

m.add(btn1);

m.add(btn2);

m.add(btn3);

m.add(btn4);

m.setVisible(true);

}

public static void main(String[] args) {

new Stmessege();

}

}

可以仿照我的做一下,希望采纳,我才一级哦

java中怎么用sql语句做修改 增加 删除的功能 不只是sql语句,要有具体的代码

结合的框架可以完成用ssh,ssi,spring MVC 等等框架都可以完成,最简单的写个basedao然后用servelt完成

Java中如何进行文件(及文件夹)的新建,移动,删除等?给出代码

File

F=new

File(路径);/通过将给定路径名字符串转换为抽象路径名来创建一个新

File

实例。

F.delete();//删除此抽象路径名表示的文件或目录。

文件的移动的话,得通过输入输出流

FileInputStream

FI=new

FileInputStream(F);

FileOutputStream

FO=new

FileOutputStream(F);

wile(FI.read()!=EOF)

{

FO.write();

}

java数组如何进行插入删除(很菜的问题)

java数组插入实现思路:

可以把某个整数插入到整型数组的特定位置,数组中原有元素向后移动

删除方法:能够从整形数组中特定位置删除掉一个元素,数组中原有元素向前移动

程序代码:

InsertDelete.java:

package p1;

import com.kettas.common.*;

import java.util.*;

public class InsertDelete

{

static int[] a={4,2,7,3,5};//初始数组

static int sum=5;//数组的有效位数

public static void main(String[] args)

{  

System.out.println("初始数组为:");

output();

while(true)

{

System.out.println("操作:1:插入;2:删除;3:退出");

int option=SystemIn.readInt();

if(option==1)

{

System.out.println("请输入插入的位置:");

int pos=SystemIn.readInt();

System.out.println("请输入要插入的数:");

int num=SystemIn.readInt();

add(pos,num);

System.out.println("插入后的数组为:");

output();

}

else if(option==2)

{

System.out.println("请输入要删除的数的位置:");

int pos1=SystemIn.readInt();

move(pos1);

System.out.println("删除后的数组为:");

output();

}

else 

break;

}

}

static void add(int pos,int num)

{  //将num插入到数组的第pos下标中,其他元素向后移动

if(sum == a.length)

{     // 扩充数组空间

a=Arrays.copyOf(a,a.length*2); 

}

for(int i=sum;ipos;i--)

{

a[i]=a[i-1]; 

}

a[pos]=num;

sum++;  //有效位数加1

}

static void move(int pos)

{  //删除数组中下标为pos的元素

sum--;  //有效位数减1

for(int i=pos;isum;i++) 

{

a[i]=a[i+1];

}  

}

static void output()

{   // 遍历输出数组中的元素

for(int i=0;isum;i++)

{

System.out.print(a[i]+" ");

}

System.out.println();

}

}

测试结果:

怎么用java向数据库中添加和删除数据

我这有个类,一直用

package com.second.dao;

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

public class JDBCUtilDao {

private static Connection con = null;

private static PreparedStatement ps = null;

private static ResultSet rs = null;

public static Connection PrintCon() {

return con;

}

public static PreparedStatement PrintPs() {

return ps;

}

public static ResultSet PrintRs() {

return rs;

}

/**

* 准备驱动

*/

static {

try {

Class.forName("net.sourceforge.jtds.jdbc.Driver");

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

System.out.println("加载驱动失败!");

e.printStackTrace();

}

}

public static Connection getConnection() {

try {

con = DriverManager.getConnection(

"jdbc:jtds:sqlserver://192.168.6.110/sql_second", "sa",

"123");

// System.out.println(con);

} catch (SQLException e) {

// TODO Auto-generated catch block

System.out.println("连接失败!");

e.printStackTrace();

}

return con;

}

/**

* 关闭连接

* @param rs

*            结果集对象

* @param ps

*            会话对象

* @param con

*            连接对象

*/

public static void closeAll(ResultSet rs, PreparedStatement ps,

Connection con) {

try {

if (null != rs) {

rs.close();

}

if (null != ps) {

ps.close();

}

if (null != con) {

con.close();

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

/**

* 设置参数

* @param params

* @param ps

*/

public static void setParams(ListString params, PreparedStatement ps) {

if (params != null) {

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

try {

ps.setString(i + 1, params.get(i));

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

/**

* 实现增、删、改

* @param sql

*            sql语句

* @param params

*            参数

* @return 修改的行数

*/

public static int doUpdata(String sql, ListString params) {

int result = 0;

try {

// 判断是否连接 不连接就把数据库连上

if (null == con || con.isClosed()) {

con = getConnection();

}

// 得到会话

ps = con.prepareStatement(sql);

// 设置参数

setParams(params, ps);

// 得到结果,即改变行数

result = ps.executeUpdate();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

closeAll(null, ps, con);

}

return result;

}

/**

* 查询

* @param T

* @param sql

* @param params

* @param t

* @return

*/

public static T ListT qureyAll(String sql, ListString params,

ClassT t) {

// 用一个集合接受返回的数据

ListT list = new ArrayListT();

// 判断是否连接

try {

if (null == con || con.isClosed()) {

con = getConnection();

}

// 操作对象

ps = con.prepareStatement(sql);

// 设置参数

setParams(params, ps);

// 返回结果集

rs = ps.executeQuery();

// 取出t中的说有方法

Method[] method = t.getDeclaredMethods();

// 取出说有列名和列数

ResultSetMetaData rsmd = rs.getMetaData();

// 获得列数

int count = rsmd.getColumnCount();

// 取出每个列列名放入数组中

String[] columns = new String[count];

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

columns[i] = rsmd.getColumnName(i + 1);

}

// 循环结果集

while (rs.next()) {

T s = (T) t.newInstance();

// 第一个循环控制列数

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

// 第二个循环控制方法名

for (int j = 0; j  method.length; j++) {

String setName = "set" + columns[i];

if (setName.equalsIgnoreCase(method[j].getName())) {// set+列名相同就是这个类得方法名

String typeName = rsmd.getColumnTypeName(i + 1);// 得到数据库中列名的类型

// int

// varchar..

//System.out.println(typeName);

if (typeName.equals("INTEGER")

|| typeName.equals("int identity")

|| typeName.equals("int")) {

method[j].invoke(s, rs.getInt(columns[i]));

} else if (typeName.equals("DECIMAL")) {

method[j].invoke(s, rs.getDouble(columns[i]));

} else if (typeName.equals("VARCHAR2")) {

method[j].invoke(s, rs.getString(columns[i]));

} else if (typeName.equals("money")) {

method[j].invoke(s, rs.getFloat(columns[i]));

} else if (typeName.equals("datetime")) {

// System.out.println(rs.getTimestamp(columns[i]));

method[j]

.invoke(s, rs.getTimestamp(columns[i]));

} else {

method[j].invoke(s, rs.getString(columns[i]));

}

}

}

}

list.add(s);

}

closeAll(rs, ps, con);

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InstantiationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InvocationTargetException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

/**

* 查询

* @param sql

* @param obj

* @return

*/

public static ResultSet getInfoos(String sql, Object[] temp) {

ResultSet rs = null;

try {

if (con == null || con.isClosed()) {

getConnection();

}

ps = con.prepareStatement(sql);

for (int i = 1; i  temp.length; i++) {

ps.setObject(i, temp[i]);

}

rs = ps.executeQuery();

} catch (SQLException e) {

e.printStackTrace();

}

return rs;

}

public static void main(String[] args) {

// JDBCUtilDemo jd = new JDBCUtilDemo();

// System.out.println(jd.getConnection());

// if(jd.updateByUserId("8888" )){

// System.out.println("OK");

// }else{

// System.out.println("NO");

// }

}

}

求Java大神把增加一行记录和删除一行记录的代码写进源程序!!!见下图

功能已实现,方案改了一下,用文体文件来存取比较麻烦,我改成用properties文件来存取(编码格式为GBK,如需手工编辑请注意用GBK编码格式保存)。

其实最好是用数据库来存取数据。

我修改的部分都加了标签。即/*** * 偶改的 start * ***/ 与/*** * 偶改的 end * ***/之间的即我修改的


当前题目:java增加和删除代码 java批量删除代码
本文路径:http://scyanting.com/article/doceice.html